// Font Replacement
Cufon.set('engine', 'canvas');
Cufon.replace('.category-title h1,' +
                '#naver li a span,' +
                '.footer h4, ' +
                '.product-view .product-shop .product-name h1,' +
                '.page-title h1,' +
                '.page-title h2,' +
                '.wired-home .subscribe strong',
        { hover: true });

var $j = jQuery.noConflict();

$j(document).ready(function() {
	// Featured Products
    if ( $j('#featured').length > 0 ) {
        $j('#featured').jcarousel();
    }
	// FancyBox jQuery
    if ( $j("a.group").length > 0 ) {
	    $j("a.group").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true });
    }
	// Slider Homepage
    if ( $j('#slider').length > 0 ) {
        $j('#slider').cycle({
            fx: 'fade',
            speed: 2000,
            timeout: 5000,
            pager: '#controls',
            slideExpr: '.panel'
        });
    }

    if ($j('#product-options-wrapper').length > 0) {

        if ($j('ul.options-list > li > input.radio').length > 3 ||
                ($j('#product-options-wrapper textarea').length == 0 &&
                 $j('ul.options-list > li > input.radio').length > 1 ) ) {
            // Default Right
            $j('ul.options-list > li > input.radio').get(0).click();

        }

        if ($j('#product-options-wrapper textarea').length > 0) {
            var count = $j('ul.options-list > li > input.radio').length;
            // Visible TextArea depends of Yes or No
            var text = $j('#product-options-wrapper.product-options dl dd.last');
            var text_title = text.prev('dt');
            text.hide(); text_title.hide();

            var no = $j('ul.options-list > li > input.radio').get(count-2);
                // Default No
                $j(no).click();
            var yes = $j('ul.options-list > li > input.radio').get(count-1);
            var ind = $j(text).children('p').children('strong');
            var max_len = $j(ind).text();
            var textarea = $j(text).children('textarea').get(0);

            no.observe('click', function(){
                text.hide();
                text_title.hide();
                textarea.innerHTML = "";
            });
            yes.observe('click', function(){
                text.show();
                text_title.show();
                textarea.innerHTML = $j("#engravedtext").val();
                $j(ind).text( max_len - $j(textarea).val().length);
            });
        }

        if ($j('#product-options-wrapper input.input-text,' +
               '#product-options-wrapper textarea').length > 0) {
            // Fucking conflict Prototype and jQuery in events
            $j('#product-options-wrapper input.input-text,' +
               '#product-options-wrapper textarea').each(function() {
                var ind = $j(this).next('p').children('strong');
                var max_len = $j(ind).text();
                // Fucking conflict Prototype and jQuery in events
                this.observe('keyup' ,function() {
                    $j(ind).text( max_len - $j(this).val().length);
                });
            });
        }
    }
});

function toggleMenu(el, over)
{
    if (Element.childElements(el)) {
    var uL = Element.childElements(el)[1];
    var iS = true;
    }
    if (over) {
        Element.addClassName(el, 'over');

        if(iS){ uL.addClassName('shown-sub')};
    }
    else {
        Element.removeClassName(el, 'over');
        if(iS){ uL.removeClassName('shown-sub')};
    }
}
