/*
 * fadeSlideShow
 * v.2.0.0
 *
 * Copyright (c) 2010 Pascal Bajorat (http://www.pascal-bajorat.com)
 * Dual licensed under the MIT
 * and GPL (http://www.gnu.org/licenses/gpl.txt) licenses.
 *
 *
 * http://plugins.jquery.com/project/fadeslideshow
 * http://www.pascal-bajorat.com
 */
 function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}
jQuery.fn.fadeSlideShow=function(options){return this.each(function(){settings=jQuery.extend({width:640,height:480,speed:'slow',interval:3000,PlayPauseElement:'fssPlayPause',PlayText:'Play',PauseText:'Pause',NextElement:'fssNext',NextElementText:'',PrevElement:'fssPrev',PrevElementText:'',ListElement:'fssList',ListLi:'fssLi',ListLiActive:'fssActive',addListToId:false,allowKeyboardCtrl:true,autoplay:true},options);jQuery(this).css({width:settings.width,height:settings.height,position:'relative',overflow:'hidden'});jQuery('> *',this).css({position:'absolute',width:settings.width,height:settings.height});Slides=jQuery('> *',this).length;Slides=Slides-1;ActSlide=Slides;jQslide=jQuery('> *',this);fssThis=this;autoplay=function(){intval=setInterval(function(){
	
	
	
	//jQslide.eq(ActSlide).fadeOut(settings.speed)
	jQuery('> *',fssThis).fadeOut(settings.speed);
	//jQuery('> *',fssThis).eq(ActSlide).fadeIn(settings.speed);
	jQuery('> *',fssThis).eq(ActSlide-1).fadeIn(settings.speed);

var newHref = jQslide.eq(ActSlide-1).children().attr('alt');

	/*$('.pt2 .plus a').click(function() {
		$('#load').load('add_art.php?id=" + newHref + "');
		$('.pt2 .plus').addClass('minus');
		
		if(getCookie("collection[id]["+ newHref +"]")!=null){
			var addArt = "$('#load').load('add_art.php?remove=";
			$(".pt2 .plus").addClass("minus");
			$('.pt2 .plus a').attr('onClick', 'remove_from('+newHref+')').not('.plus1').text('Remove from Collection');
			//add_to(newHref);
		}else{
			var addArt = "$('#load').load('add_art.php?id=";
			$(".pt2 .minus").removeClass("minus");
			$('.pt2 .plus a').attr('onClick', 'add_to('+newHref+')').not('.plus1').text('Add Image to My Collection Box');
			//remove_from(newHref);
		} 
		
	});*/

	if(getCookie("collection[id]["+ newHref +"]")!=null){
		var addArt = "$('#load').load('add_art.php?remove=";
		$(".pt2 .plus").addClass("minus");
		$('.pt2 .plus a').attr('onClick', 'remove_from('+newHref+')').not('.plus1').text('Remove from Collection');
		//add_to(newHref);
	}else{
		var addArt = "$('#load').load('add_art.php?id=";
		$(".pt2 .minus").removeClass("minus");
		$('.pt2 .plus a').attr('onClick', 'add_to('+newHref+')').not('.plus1').text('Add Image to My Collection Box');
		//remove_from(newHref);
	} 



if(settings.ListElement){setActLi=(Slides-ActSlide)+1;if(setActLi>Slides){setActLi=0;}
jQuery('#'+settings.ListElement+' li').removeClass(settings.ListLiActive);jQuery('#'+settings.ListElement+' li').eq(setActLi).addClass(settings.ListLiActive);}
if(ActSlide<=0){
	
	//jQslide.fadeIn(settings.speed);
	ActSlide=Slides;
	
	}else{ActSlide=ActSlide-1;}},settings.interval);if(settings.PlayPauseElement){jQuery('#'+settings.PlayPauseElement).html(settings.PauseText);}}
stopAutoplay=function(){clearInterval(intval);intval=false;if(settings.PlayPauseElement){jQuery('#'+settings.PlayPauseElement).html(settings.PlayText);}}
jumpTo=function(newIndex){if(newIndex<0){newIndex=Slides;}
else if(newIndex>Slides){newIndex=0;}
/*if(newIndex>=ActSlide){
		//console.log(newIndex);
		console.log(jQuery('> *',fssThis).eq(newIndex));
		//jQuery('> *:lt('+(newIndex+1)+')',fssThis)
		//jQuery('> *:lt('+(newIndex+1)+')',fssThis).fadeIn(settings.speed);
		jQuery('> *',fssThis).eq(newIndex).fadeIn(settings.speed);
	}else if(newIndex<=ActSlide){
		console.log(jQuery('> *',fssThis).eq(newIndex));
		jQuery('> *:gt('+newIndex+')',fssThis).fadeOut(settings.speed);
	
	}*/
	jQuery('> *',fssThis).fadeOut(settings.speed);
	jQuery('> *',fssThis).eq(newIndex).fadeIn(settings.speed);
ActSlide=newIndex;if(settings.ListElement){jQuery('#'+settings.ListElement+' li').removeClass(settings.ListLiActive);jQuery('#'+settings.ListElement+' li').eq((Slides-newIndex)).addClass(settings.ListLiActive);}}
if(settings.ListElement){i=0;li='';while(i<=Slides){
	if(i==0){li=li+'<li class="'+settings.ListLi+i+' '+settings.ListLiActive+'"><a href="#"><\/a><\/li>';}else{li=li+'<li class="'+settings.ListLi+i+'"><a href="#"><\/a><\/li>';
}
/*	$('#slideshow li img').eq(i).wrap('<a href="#" class="special"></a>')
	$('#slideshow li a').eq(i).bind('click',function(){
		var total = $('#slideshow li img').length;
		index= total - $('#slideshow li a').index($(this));
		stopAutoplay();
		ReverseIndex=Slides-index;
		jumpTo(ReverseIndex);
		return false;
	})

*/
i++;
}
List='<ul id="'+settings.ListElement+'">'+li+'<\/ul>';if(settings.addListToId){jQuery('#'+settings.addListToId).append(List);}else{jQuery(this).after(List);}
jQuery('#'+settings.ListElement+' a').bind('click',function(){index=jQuery('#'+settings.ListElement+' a').index(this);stopAutoplay();ReverseIndex=Slides-index;jumpTo(ReverseIndex);

var newHref = jQslide.eq(ActSlide).children().attr('alt');
	if(getCookie("collection[id]["+ newHref +"]")!=null){
		var addArt = "$('#load').load('add_art.php?remove=";
		$(".pt2 .plus").addClass("minus");
		$('.pt2 .plus a').attr('onClick', 'remove_from('+newHref+')').not('.plus1').text('Remove from Collection');
		//add_to(newHref);
	}else{
		var addArt = "$('#load').load('add_art.php?id=";
		$(".pt2 .minus").removeClass("minus");
		$('.pt2 .plus a').attr('onClick', 'add_to('+newHref+')').not('.plus1').text('Add Image to My Collection Box');
		//remove_from(newHref);
	} 




return false;});}
if(settings.PlayPauseElement){if(!jQuery('#'+settings.PlayPauseElement).css('display')){jQuery(this).after('<a href="#" id="'+settings.PlayPauseElement+'"><\/a>');}
if(settings.autoplay){jQuery('#'+settings.PlayPauseElement).html(settings.PauseText);}else{jQuery('#'+settings.PlayPauseElement).html(settings.PlayText);}
jQuery('#'+settings.PlayPauseElement).bind('click',function(){if(intval){stopAutoplay();}else{autoplay();}
return false;});}
/*
jQuery('.plus').hover(function() {
	stopAutoplay();	
}, function() {
	autoplay();
});
*/
if(settings.NextElement){if(!jQuery('#'+settings.NextElement).css('display')){jQuery(this).after('<a href="#" id="'+settings.NextElement+'">'+settings.NextElementText+'<\/a>');}
jQuery('#'+settings.NextElement).bind('click',function(){nextSlide=ActSlide-1;stopAutoplay();jumpTo(nextSlide);return false;});}
if(settings.PrevElement){if(!jQuery('#'+settings.PrevElement).css('display')){jQuery(this).after('<a href="#" id="'+settings.PrevElement+'">'+settings.PrevElementText+'<\/a>');}
jQuery('#'+settings.PrevElement).bind('click',function(){prevSlide=ActSlide+1;stopAutoplay();jumpTo(prevSlide);return false;});}
if(settings.allowKeyboardCtrl){jQuery(document).bind('keydown',function(e){
	
	if(e.which==39){
		nextSlide=ActSlide-1;
		stopAutoplay();
		jumpTo(nextSlide);
var newHref = jQslide.eq(ActSlide).children().attr('alt');
	if(getCookie("collection[id]["+ newHref +"]")!=null){
		var addArt = "$('#load').load('add_art.php?remove=";
		$(".pt2 .plus").addClass("minus");
		$('.pt2 .plus a').attr('onClick', 'remove_from('+newHref+')').not('.plus1').text('Remove from Collection');
		//add_to(newHref);
	}else{
		var addArt = "$('#load').load('add_art.php?id=";
		$(".pt2 .minus").removeClass("minus");
		$('.pt2 .plus a').attr('onClick', 'add_to('+newHref+')').not('.plus1').text('Add Image to My Collection Box');
		//remove_from(newHref);
	} 


	}else if(e.which==37){
		prevSlide=ActSlide+1;
		stopAutoplay();
		jumpTo(prevSlide);
var newHref = jQslide.eq(ActSlide).children().attr('alt');
	if(getCookie("collection[id]["+ newHref +"]")!=null){
		var addArt = "$('#load').load('add_art.php?remove=";
		$(".pt2 .plus").addClass("minus");
		$('.pt2 .plus a').attr('onClick', 'remove_from('+newHref+')').not('.plus1').text('Remove from Collection');
		//add_to(newHref);
	}else{
		var addArt = "$('#load').load('add_art.php?id=";
		$(".pt2 .minus").removeClass("minus");
		$('.pt2 .plus a').attr('onClick', 'add_to('+newHref+')').not('.plus1').text('Add Image to My Collection Box');
		//remove_from(newHref);
	} 

	}else if(e.which==32){
		if(intval){
			stopAutoplay();
		}
		else{autoplay();
	}
	return false;
	}
});}
if(settings.autoplay){autoplay();}else{intval=false;}});};

//HOVER INTENT JS

(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);
//$("a.offsite").live("click", function(){ alert("Goodbye!"); }); 
		$('#popup-close').live('click', function() {
			$(this).parent().remove();
		});
