// JavaScript Document
jQuery(document).ready(function(){
	
	jQuery(".articalWrap").each(function(){
		if(jQuery(this).parent().children(".articalWrap").length <= 1){
			jQuery(this).css({
				'border-bottom'		:	'none',
				'margin-bottom'		:	'0'
			});
		}
	});

	_path = window.location.host;	
	jQuery("#side_slide .cat-item").each(function(){	
		_catID = jQuery(this).attr("class").split(" ")[1].split("-")[2];
		jQuery(this).css({"background" : "url('http://"+_path+"/wordpress/category/cat-"+_catID+".png') left top no-repeat"});
	});

	jQuery("#side_slide .cat-item a").focus(function(){
		this.blur();
	});
	
	jQuery("#side_slide ul li a").each(function(){
		if(jQuery(this).parent().children("ul").length>0){
			jQuery(this).css("cursor","default");
		}
	});

	jQuery(".category-voice #voice-conts .single a").each(function(){
		if(jQuery(this).children("img").length > 0){
			jQuery(this).attr("target","_blank");
		}
	});
				  
	//side_silide init
	jQuery("#side_slide ul li a").attr("href","#");
	jQuery("#side_slide>ul>li:first").addClass("current");
	jQuery("#side_slide>ul>li:first").addClass("now");
	jQuery("#conts_slide div.entry").hide();
	
	if(jQuery("#side_slide>ul>li:first").children("ul").length > 0){
		init = jQuery("#side_slide ul.children li:first");
		_catID = init.attr("class").split(" ")[1].split("-")[2];
		init.addClass("current");
		init.css({"background" : "url('http://"+_path+"/wordpress/category/cat-"+_catID+"-over.png') left top no-repeat"});		
		jQuery("#conts_slide div.entry").eq(1).show();
	}else{
		jQuery("#conts_slide div.entry").eq(0).show();
	}
	
			 
	//hover
	jQuery("#side_slide ul.children li").hover(function(){
		_parent = jQuery(this).parent().parent();
		_parent.addClass("current");

		_catID = jQuery(this).attr("class").split(" ")[1].split("-")[2];
		jQuery(this).css({"background" : "url('http://"+_path+"/wordpress/category/cat-"+_catID+"-over.png') left top no-repeat"});
	},function(){
		if(!jQuery(this).hasClass("current")){
			_catID = jQuery(this).attr("class").split(" ")[1].split("-")[2];
			jQuery(this).css({"background" : "url('http://"+_path+"/wordpress/category/cat-"+_catID+".png') left top no-repeat"});
		} 
		
		if(!jQuery(this).parent().parent().hasClass("now")){			
			jQuery(this).parent().parent().removeClass("current");
		}
	});

	jQuery("#side_slide>ul>li").hover(
		function(){
			jQuery(this).addClass("current");
		},
		function(){
			if(!jQuery(this).hasClass("now")){
				jQuery(this).removeClass("current");
			}
		}
	);
	
	//click	
	jQuery("#side_slide ul.children li a").click(function(){
			_index = jQuery("#side_slide ul li a").index(jQuery(this));
			jQuery("#conts_slide div.entry").hide();
			jQuery("#conts_slide div.entry").eq(_index).show();

			jQuery("#side_slide ul.children li.current").removeClass("current");
			jQuery(this).parent().addClass("current");
					
			jQuery("#side_slide .cat-item").each(function(){	
				_catID = jQuery(this).attr("class").split(" ")[1].split("-")[2];
				jQuery(this).css({"background" : "url('http://"+_path+"/wordpress/category/cat-"+_catID+".png') left top no-repeat"});
			});
					
			_catID = jQuery(this).parent().attr("class").split(" ")[1].split("-")[2];
			jQuery(this).parent().css({"background" : "url('http://"+_path+"/wordpress/category/cat-"+_catID+"-over.png') left top no-repeat"});

			_parent = jQuery(this).parent().parent().parent();
			if(!_parent.hasClass("now")){
				jQuery("#side_slide>ul>li.now").removeClass("current");
				jQuery("#side_slide>ul>li.now").removeClass("now");
				_parent.addClass("now");
				_parent.addClass("current");
			}

			return false;
	});

	jQuery("#side_slide>ul>li>a").click(function(){
			if(jQuery(this).next("ul").length <= 0){
				jQuery("#side_slide .cat-item").each(function(){
					jQuery(this).removeClass("current");
					_catID = jQuery(this).attr("class").split(" ")[1].split("-")[2];
					jQuery(this).css({"background" : "url('http://"+_path+"/wordpress/category/cat-"+_catID+".png') left top no-repeat"});
				});
	
				if(!jQuery(this).parent().hasClass("now")){
					jQuery("#side_slide ul li.now").removeClass("current");
					jQuery("#side_slide ul li.now").removeClass("now");
				}
	
				jQuery(this).parent().addClass("now");
				jQuery(this).parent().addClass("current");
	
				_index = jQuery("#side_slide ul li a").index(jQuery(this));
				jQuery("#conts_slide div.entry").hide();
				jQuery("#conts_slide div.entry").eq(_index).show();
			}
			return false;
	});


	//style revise
	jQuery(".category-media .cat-item-46 #ngg-gallery-3-114 .ngg-gallery-thumbnail a img:odd").css({'margin-right':"0"});
	jQuery(".category-media .cat-item-46 #ngg-gallery-30-114 .ngg-gallery-thumbnail a img").eq(3).css({'margin-right':"0"});
    jQuery(".category-media .cat-item-46 .ngg-gallery-thumbnail a").attr('target','_blank');
	
	jQuery(".category-media #ngg-gallery-29-112 .ngg-gallery-thumbnail a img").eq(5).css('margin-right',"0");	
	jQuery(".category-media #ngg-gallery-29-112 .ngg-gallery-thumbnail a img").eq(11).css('margin-right',"0");
    
	jQuery(".category-media .cat-item-47 .ngg-gallery-thumbnail a").addClass("thickbox");
	jQuery(".category-gear .ngg-gallery-thumbnail-box .ngg-gallery-thumbnail a").addClass("thickbox");
	
	for(var i=4;i<10;i+=5){
		jQuery(".category-gear #conts_slide .cat-item-11 .ngg-galleryoverview").each(
			function(){
				if(jQuery(this).children(".ngg-gallery-thumbnail-box").length >= 5){
					jQuery(this).children(".ngg-gallery-thumbnail-box").children(".ngg-gallery-thumbnail").eq(i).children("a").children("img").css('margin-right',"0");
					jQuery(this).children(".ngg-gallery-thumbnail-box").children(".ngg-gallery-thumbnail").eq(i).parent().css('clear','right');
				}
			}
		);
		
		jQuery(".category-gear #conts_slide .cat-item-16 .ngg-galleryoverview").each(
			function(){
				if(jQuery(this).children(".ngg-gallery-thumbnail-box").length >= 5){
					jQuery(this).children(".ngg-gallery-thumbnail-box").children(".ngg-gallery-thumbnail").eq(i).children("a").children("img").css('margin-right',"0");
					jQuery(this).children(".ngg-gallery-thumbnail-box").children(".ngg-gallery-thumbnail").eq(i).parent().css('clear','right');
				}
			}
		);
		
		jQuery(".category-gear #conts_slide .cat-item-15 .ngg-galleryoverview").each(
			function(){
				if(jQuery(this).children(".ngg-gallery-thumbnail-box").length >= 5){
					jQuery(this).children(".ngg-gallery-thumbnail-box").children(".ngg-gallery-thumbnail").eq(i).children("a").children("img").css('margin-right',"0");
					jQuery(this).children(".ngg-gallery-thumbnail-box").children(".ngg-gallery-thumbnail").eq(i).parent().css('clear','right');
				}
			}
		);
	}
    
    for(var i=9;i<30;i+=10){
		jQuery(".category-gear #conts_slide .cat-item-13 .ngg-galleryoverview").each(
			function(){
				if(jQuery(this).children(".ngg-gallery-thumbnail-box").length >= 10){
					jQuery(this).children(".ngg-gallery-thumbnail-box").children(".ngg-gallery-thumbnail").eq(i).children("a").children("img").css('margin-right',"0");
				}
			}
		);
	} 
	
	jQuery("#showDownload").click(function(){
		jQuery('#overlayDiv').css("height",document.documentElement.scrollHeight + "px");
	
		jQuery('#overlayDiv').show();
	
		jQuery('#download').show();
	});
	
	jQuery("#closeDownload").click(function(){
		jQuery('#overlayDiv').hide();	
		jQuery('#download').hide();
	});

	//revise the wallpaper
    if(jQuery(".category-media")){
        var address = window.location.toString();
        if(address == jQuery("#index").val()){
            jQuery("#side_slide>ul>li").removeClass("current");
			jQuery("#side_slide>ul>li").removeClass("now");
            jQuery("#side_slide>ul>li").eq(1).addClass("current");
            jQuery("#side_slide>ul>li").eq(1).addClass("now");
            jQuery("#conts_slide div.entry").hide();
    		jQuery("#conts_slide div.entry").eq(1).show();
        }
    }
								
	//reset the lightbox image group rel attribute
	jQuery(".ngg-galleryoverview").each(function(){
		_index = jQuery(".ngg-galleryoverview").index(jQuery(this));
		jQuery(this).children("div").children("div").children("a").attr("rel","thickbox-"+_index);
	});

	jQuery("p.attachment a").attr('target','_blank');
	jQuery("div.open-new .single .text a").each(function(){
		if(jQuery(this).children("img").length > 0){
			jQuery(this).attr('target','_blank');
		}
	});
});