//idle/timeout
jQuery.fn.idle = function(time){  
	var i = $(this);  
	i.queue(function(){  
		setTimeout(function(){  
			i.dequeue();  
		}, time);  
	});  
};  
	
//hoverintent plugin
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);

//xmenu plugin
function showm() { $(this).children('ul').slideDown('fast'); }
function hidem() { $(this).children('ul').slideUp('fast'); }
;(function($){
	$.fn.xmenu = function(op){
		var flvl = $(this).children('ul').children('li'); var flvllength = flvl.length; $(flvl).addClass('flvl');
		$(flvl).hoverIntent({
			over: showm,
			timeout: 200,
			out: hidem
		});
	}
})(jQuery);


var c=0;
var t;
var timer_is_on=0;
var numberli = $("#banner ul li").length;
var currentSlide;
var currentactiveli;
var nextSlide;
function timedCount() {
	$("#banner li").each(function() {
		var currentactiveli = $(this).hasClass("active");
		if(currentactiveli == true){
			currentSlide = $(this);
			nextSlide = $(currentSlide).next();
			if($(nextSlide).length == 0) {
				nextSlide = $("#banner li:first-child");
			}
		}
	});
	
	$(currentSlide).animate({width: "36px"}, {duration:800, queue:false}).removeClass("active");
	$(nextSlide).animate({width: "730px"}, {duration:800, queue:false}).addClass("active");
	
	c=c+1;
	t=setTimeout("timedCount()",4000);
}
function doTimer() {
	if (!timer_is_on) {
		timer_is_on=1;
		timedCount();
	}
}

function stopCount() {
	clearTimeout(t);
	timer_is_on=0;
}

function domagic() {
	activeItem = $("#banner").find("li.active");
	if (activeItem.length == 0) {
		activeItem = $("#banner li:first-child");
	}
    $(activeItem).addClass("active");
 
    $("#banner li").hover(function(){
		stopCount();
        $(activeItem).animate({width: "36px"}, {duration:800, queue:false});
		$("#banner li").each(function() {
			$(this).animate({width: "36px"}, {duration:800, queue:false});
		})
        $(this).animate({width: "730px"}, {duration:800, queue:false});
        activeItem = this;
		$("#banner li").each(function() {
			$(this).removeClass("active");
		});
		$(activeItem).addClass("active");
    },function() {
		t=setTimeout("timedCount()",4000);
	});
	
	$(".ngg-galleryoverview .ngg-gallery-thumbnail-box h4").hover(function() {
		$(this).css("padding","10px");
	},function() {
		$(this).css("padding","5px 10px");
	});
	
	//do the initial timer
	t=setTimeout("timedCount()",4000);
	
	$("#menu ul li").each(function() {
		$(this).before("<li class='bull'>&bull;</li>");
	});
	$("#menu li.bull:first-child").css("display","none");
	$("#menu ul ul li.bull:first-child").css("display","list-item");
	$("#menu").append("<div class='clear'></div>");
	$('#menu').xmenu();
	$('#weather').weatherfeed(['ASXX0230','ASXX0023','ASXX0075','ASXX0016','ASXX0001','ASXX0112','ASXX0332','ASXX0032']);
	$('.ngg-galleryoverview .ngg-gallery-thumbnail-box:nth-child(5n), .prod-category-list li:last-child').css("margin-right","0");
	$(".prod-category-list li:nth-child(2)").css("background-image","url(/wp-content/themes/portablecoolingsolutions/images/prod-cat-bg-2.png)");
	$(".prod-category-list li:nth-child(3)").css("background-image","url(/wp-content/themes/portablecoolingsolutions/images/prod-cat-bg-3.png)");
	$(".prod-category-list li:nth-child(4)").css("background-image","url(/wp-content/themes/portablecoolingsolutions/images/prod-cat-bg-5.png)");
	$(".prod-category-list li:nth-child(5)").css("background-image","url(/wp-content/themes/portablecoolingsolutions/images/prod-cat-bg-4.png)");
	$(".prod-category-list li:nth-child(6)").css("background-image","url(/wp-content/themes/portablecoolingsolutions/images/prod-cat-bg-6.png)");
	/* ** cycling **
	$(".banner-slide").cycle({fx:'fade',speed:1000,timeout:8000,height:'314px',cleartypeNoBg:true,pager:'.slidepane'});
	*/
	/* ** lightbox **
	$("#content.assets .ngg-gallery-thumbnail-box .ngg-gallery-thumbnail a").lightBox({
		imageLoading: '/wp-content/themes/kis/js/images/lightbox-ico-loading.gif',
		imageBtnClose: '/wp-content/themes/kis/js/images/lightbox-btn-close.gif',
		imageBtnPrev: '/wp-content/themes/kis/js/images/lightbox-btn-prev.gif',
		imageBtnNext: '/wp-content/themes/kis/js/images/lightbox-btn-next.gif',
		imageBlank: '/wp-content/themes/kis/js/images/lightbox-blank.gif'
	});
	*/
}
