var $ = jQuery.noConflict();

$(document).ready(function() {
	// GNB animation
	$('.gnb ul li').hoverIntent(function() {
		$(this).children('.subgnb').slideDown('fast');
		$(this).addClass('hover');
	}, function() {
		$(this).children('.subgnb').slideUp('normal');
		$(this).removeClass('hover');
	});

	// Searchform change class
	$('#searchform1 #s').click(function() {
		$(this).val('');
		$(this).addClass('on');
	});
	$('#searchform1 #s').blur(function() {
		$(this).removeClass('on');
		if ($(this).val()=="") {
			$(this).val('어떤 제품을 찾으세요?');
		}
	});

	// To show product images
	$('.prd_img dd img').click(function() {
		var imgsrc=$(this).attr('src');
		$('.prd_img dt img').hide();
		$('.prd_img dt img').attr('src', imgsrc);
		$('.prd_img dt a').attr('href', imgsrc);
		$('.prd_img dt img').fadeIn('fast');
	});

	// layer popup for send email
	$("a[rel^='email']").prettyPhoto({theme:'light_rounded'});

	// To control img size of category list
	var imgsize=$('.cnt_list').children().siblings('.clist');
	for (var i=0; i<imgsize.length; i++) {
		var getsize=$(imgsize).eq(i).children('dd').children('.img').children('span').width();
		if (getsize<=284 && getsize!=null) {
			$(imgsize).eq(i).addClass('lsetc');
		} else {
			$(imgsize).eq(i).addClass('lsbig');
		}
	}

	// To show layer of layer popup on ad category
	$('.adlist dt').hoverIntent(function() {
		$(this).children('.hover').stop().animate({opacity: "0.8"}, 100);
	}, function() {
		$(this).children('.hover').stop().animate({opacity: "0"}, 100);
	});
	$("a[rel^='ad']").prettyPhoto({theme:'light_rounded', showTitle:false});

	// To show big image of product
	$("a[rel^='product']").prettyPhoto({theme:'light_rounded', showTitle:false});

	// Mouseover at map
	$('.map a').hoverIntent(function() {
		$(this).parent('.hover').addClass('over');
	}, function() {
		$(this).parent('.hover').removeClass('over');
	});

	// To rolling KEEN PHOTOS
	$('.smroll').cycle({
		fx: 'fade',
		speed:  1000,
		timeout: 3000,
		pause:1
	});

	// Twitter animation
	$('.aktt_tweets ul').cycle({
		fx: 'fade',
		speed:  1000,
		timeout: 3000,
		pause:1
	});

	// To rolling product of main
	$('.imgset').cycle({
		fx:'scrollHorz',
		speed:1000,
		timeout:5000,
		pause:1,
		pager:"#mnavset",
		pagerAnchorBuilder:(function(idx, slide) {
			return '<a href="#" title=""></a>';
		}),
		activePagerClass: "on",
		next:"#mnext",
		prev:"#mprev",
		cleartypeNoBg:true
	});

	// main animation
	/*$('#slider').cycle({
		fx:'fade',
		speed:1000,
		timeout:4000,
		prev:'#mvprev',
		next:'#mvnext',
		onPrevNextEvent:(function(isNext, zeroBasedSlideIndex, slideElement) {
			$('#homebg').cycle(zeroBasedSlideIndex);
		}),
		before:onBefore,
		cleartypeNoBg:true
	});*/
	$('#slider').cycle({
		fx:'fade',
		speed:2000,
		timeout:4000,
		cleartypeNoBg:true
	});
	$('#homebg').cycle({
		fx:'zoom',
		speed:1000,
		timeout:4000,
		after:(function(currSlideElement, nextSlideElement, options, forwardFlag){
			$('.nav li').removeClass('on');
			$('.nav li:eq('+options.currSlide+')').addClass('on');
		}),
		cleartypeNoBg:true
	});
	
	// Submain
	$('#subbigimg').cycle({
		fx:'fade',
		speed:500,
		timeout:4000,
		next:"#subnext",
		prev:"#subprev",
		cleartypeNoBg:true
	});
	$('#subsmimg').cycle({
		fx:'scrollHorz',
		speed:500,
		timeout:4000,
		next:"#subnext",
		prev:"#subprev",
		cleartypeNoBg:true
	});
	
	// Movie roll
	$('.video').cycle({
      	fx:     'fade',
		speed:  'fast',
      	timeout: 3000,
        pager:  '#vnavset',
        pause: 'true',
		pagerAnchorBuilder:(function(idx, slide) {
			return '<a href="#" title=""></a>';
		}),
		activePagerClass: "on",
        pauseOnPagerHover: 'true',
		before: function() { if (window.console) console.log(this.src); }
    });


	// lazy load image
	$('.cnt_idx img').lazyload({effect:'fadeIn',placeholder:'/wp-content/themes/v6/_base/img/blank.png'});
});

// Callback cycle
function onBefore() {
	//$(this).fadeIn();
}

// display tabs on sidebar
function displays (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();
		}
	}
}

// remove anchor
function bluring(){
	if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus();
}
document.onfocusin=bluring;

// Submit for store
function chkstore() {
	var blogurl=$('#blogurl').val();
	var page_id=$('#page_id').val();
	var stores=$('#stores').val();
	var what=$('#what').val();
	location.replace(blogurl+'?page_id='+page_id+'&what='+what+'&stores='+stores);
	return false;
}
// Change main background
function change_main(value) {
	$('#homebg').cycle(value);
	$('#slider').cycle(value);
	$('.nav li').removeClass('on');
	$('.nav li:eq('+value+')').addClass('on');
}
