var $ = jQuery.noConflict();

$(document).ready(function() {
	// To rolling in main visual
	/*$('#smv').cycle({
		fx:'fade',
		speed:3000,
		timeout:5000,
		pause:1,
		pager:"#snv",
		pagerAnchorBuilder:(function(idx, slide) {
			return '<a href="#" title=""></a>';
		}),
		activePagerClass: "on"
	});*/

	// Animation of menu
	$("#menu ul li").eachDelay(function(){
		$(this).stop().animate(
			{marginLeft: '0px'},
			1000,
			'easeOutBack');
		},
	30);

	// Searchform change class
	$('#searchform1 #s').click(function() {
		$(this).addClass('on');
	});
	$('#searchform1 #s').blur(function() {
		if ($(this).val()=="") {
			$(this).removeClass('on');
		}
	});

	// SlideDown on sidebar
	$('.select, .pselect').hoverIntent(function() {
		$(this).children('ul').slideDown('fast');
		$(this).children('ul').addClass('open');
	}, function() {
		$(this).children('ul').slideUp('fast');
		$(this).children('ul').removeClass('open');
	});

	// Star Tab
	$('.sintro li a').click(function() {
		var wtab=$(this).attr('class');
		for (var i=1; i<=13; i++) {
			$('#star'+i).fadeOut();
			$('.sintro li').removeClass('on');
		}
		$('#'+wtab).fadeIn('slow');
		$('#'+wtab+' .sinfo1 .img img').fadeOut('slow');
		$('#'+wtab+' .sinfo1 .img img').fadeIn('slow');
		$(this).parent('li').addClass('on');
	});

	// Shop rolling at category page
	$("#slider_roll").jcarousel({
		auto:1,
		scroll:1,
		wrap:'circular',
		buttonNextHTML:null,
		buttonPrevHTML:null,
		animation:1000,
		initCallback:s_callback,
		itemFirstInCallback:s_first_callback,
		itemLastOutCallback:s_first_out_callback
	});
	$('.idxslide li a').hoverIntent(function() {
		$(this).children('span').css('display', 'block');
	}, function() {
		$(this).children('span').css('display', 'none');
	});

	// view big img
	$("a[rel^='bigimg']").prettyPhoto({theme:'light_rounded'});
});

// main rolling in category callback function
function s_first_callback(carousel, item, idx, state) {
	$('#slider_roll li.jcarousel-item-'+idx+' span').css('display', 'block');
	var cgclass=$('#slider_roll li.jcarousel-item-'+idx+' a').attr('class');
	for (var i=1; i<=12; i++) {
		if (i==cgclass) {
			$('#bgbodybg .idx'+i).fadeIn('slow');
		}
		else {
			$('#bgbodybg .idx'+i).fadeOut('slow');
		}
	}

};
function s_first_out_callback(carousel, item, idx, state) {
	var iidx=idx-4;
	$('#slider_roll li.jcarousel-item-'+iidx+' span').css('display', 'none');
};

function s_callback(carousel, item, idx, state) {
    $('#nextimg').bind('click', function() {
        carousel.next();
        return false;
    });
    $('#previmg').bind('click', function() {
        carousel.prev();
        return false;
    });
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}

// display tabs on sidebar
function sidedisplay (value, total, tabid, divid) {
	for (var i=1; i<=total; i++) {
		if (value==i) {
			$(tabid+i).addClass("on");
			$(divid+i).slideDown('fast');
		}
		else {
			$(tabid+i).removeClass("on");
			$(divid+i).hide();
		}
	}
}

// display star tab
function star(value) {
	if(value > 4 && value < 8) { 
		var vals=value-2; 
	} else {
		var vals=value-1;
	}
	for (var i=0; i<13; i++) {
		var ri=i+1;
		if (i==vals) {
			if(value > 4 && value < 8) { 
				var ri=i+2;
			}
			$('.sintro ul li:eq('+i+')').addClass('on');
			$('#star'+ri).show();
		}	else {
			if(i > 0 && (value > 4  && value < 8)) { 
				var ri=i+2;
			}
			$('.sintro ul li:eq('+i+')').removeClass('on');
			$('#star'+ri).hide();
		}
	}
}

// Check Newsletter
function chk_newsletter() {
	if ($('#email').val()=="") {
		alert("이메일 주소가 올바르지 않습니다.");
		return false;
	}
	else {
		window.open('http://feedburner.google.com/fb/a/mailverify?uri=bhent', 'popupwindow', 'scrollbars=yes,width=550,height=520');
		return true;
	}
}
