/*
Supersized - Fullscreen Slideshow jQuery Plugin
By Sam Dunn (www.buildinternet.com // www.onemightyroar.com)
Version: supersized.2.0.js // Relase Date: 5/7/09
Website: www.buildinternet.com/project/supersized
Thanks to Aen for preloading, fade effect, & vertical centering
*/

var iFadeInTransitionTime = 1750;

(function($){

	//Resize image on ready or resize
	$.fn.supersized = function() {
		$.inAnimation = false;
		$.paused = false;
		var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
		
		$(window).bind("load", function(){
			$('#loading').hide();
			
			//load initial special
			if (options.slide_captions == 1) {
				var $specialsSlide = $('#specialsGroup #specialSlideContents').eq(0);
				$('#specialsSlideThumb img').attr('src', $specialsSlide.attr('thumb'));
				$('#specialsSlideHeader').html($specialsSlide.attr('header'));
				$('#specialsSlideDescription').html($specialsSlide.attr('description'));
				$('#specialsSlideLink a').html($specialsSlide.attr('linkText'));
				$('#specialsSlideLink a').attr('href', $specialsSlide.attr('link'));
			}

			$('#supersize').fadeIn('fast');
			$('#content').show();
			if ($('#slideshow .activeslide').length == 0) $('#supersize a:first').addClass('activeslide');
			if (options.slide_captions == 1) $('#slidecaption').html($('#supersize .activeslide').find('img').attr('title'));
			if (options.navigation == 0) $('#navigation').hide();
			//Slideshow
			if (options.slideshow == 1){
				//if (options.slide_counter == 1){ //Initiate slide counter if active
					$('#slidecounter .slidenumber').html(1);
	    			$('#slidecounter .totalslides').html($("#supersize > *").size());
	    		//}
				slideshow_interval = setInterval("nextslide()", options.slide_interval);
				if (options.navigation == 1){ //Skip if no navigation
					$('#navigation a').click(function(){  
   						$(this).blur();  
   						return false;  
   					}); 	
					//Slide Navigation
				    $('#nextslide').click(function() {
				    	if($.paused) return false; if($.inAnimation) return false;
					    clearInterval(slideshow_interval);
					    nextslide();
					    slideshow_interval = setInterval(nextslide, options.slide_interval);
					    return false;
				    });
				    $('#prevslide').click(function() {
				    	if($.paused) return false; if($.inAnimation) return false;
				        clearInterval(slideshow_interval);
				        prevslide();
				        slideshow_interval = setInterval(nextslide, options.slide_interval);
				        return false;
				    });
					$('#nextslide img').hover(function() {
						if($.paused == true) return false;
					   	$(this).attr("src", "/SiteBase/wrap/theme0/images/specials_icon_forward_on.png");
					}, function(){
						if($.paused == true) return false;
					    $(this).attr("src", "/SiteBase/wrap/theme0/images/specials_icon_forward_off.png");
					});
					$('#prevslide img').hover(function() {
						if($.paused == true) return false; 
					    $(this).attr("src", "/SiteBase/wrap/theme0/images/specials_icon_back_on.png");
					}, function(){
						if($.paused == true) return false;
					    $(this).attr("src", "/SiteBase/wrap/theme0/images/specials_icon_back_off.png");
					});
					
				    //Play/Pause Button
				    $('#pauseplay').click(function() {
				    	if($.inAnimation) return false;
				    	var src = ($(this).find('img').attr("src") === "/SiteBase/wrap/theme0/images/specials_icon_play_on.png") ? "/SiteBase/wrap/theme0/images/specials_icon_pause_on.png" : "/SiteBase/wrap/theme0/images/specials_icon_play_on.png";
      					if (src == "/SiteBase/wrap/theme0/images/specials_icon_pause_on.png"){
      						$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_play_on.png");
      						$.paused = false;
					        slideshow_interval = setInterval(nextslide, options.slide_interval);  
				        }else{
				        	$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_pause_on.png");
				        	clearInterval(slideshow_interval);
				        	$.paused = true;
				        }
      					$(this).find('img').attr("src", src);
					    return false;
				    });
				    $('#pauseplay').mouseover(function() {
				    	var imagecheck = ($(this).find('img').attr("src") === "/SiteBase/wrap/theme0/images/specials_icon_play_off.png");
				    	if (imagecheck){
      						$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_play_on.png"); 
				        }else{
				        	$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_pause_on.png");
				        }
				    });
				    
				    $('#pauseplay').mouseout(function() {
				    	var imagecheck = ($(this).find('img').attr("src") === "/SiteBase/wrap/theme0/images/specials_icon_play_on.png");
				    	if (imagecheck){
      						$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_play_off.png"); 
				        }else{
				        	$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_pause_off.png");
				        }
				        return false;
				    });
				}
			}
		});
				
		$(document).ready(function() {
			$('#supersize').resizenow(); 
		});
		
		//Pause when hover on image
		//$('#supersize > *').hover(function() {
		// pause when the spcecials table is hovered over
		$('#tblSpecials').hover(function() {
	   		if (options.slideshow == 1 && options.pause_hover == 1){
	   			if(!($.paused) && options.navigation == 1){
	   				$('#pauseplay > img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_pause_on.png"); 
	   				clearInterval(slideshow_interval);
	   			}
	   		}
	   		original_title = $(this).find('img').attr("title");
	   		if($.inAnimation) return false; else $(this).find('img').attr("title","");
	   	}, function() {
			if (options.slideshow == 1 && options.pause_hover == 1){
				if(!($.paused) && options.navigation == 1){
					$('#pauseplay > img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_pause_off.png");
					slideshow_interval = setInterval(nextslide, options.slide_interval);
				} 
			}
			$(this).find('img').attr("title", original_title);	
	   	});
		
		$(window).bind("resize", function(){
    		$('#supersize').resizenow(); 
		});
		
		$('#supersize').hide();
		$('#content').hide();
	};
	
	//Adjust image size
	$.fn.resizenow = function() {
		var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
	  	return this.each(function() {
	  		
			//Define image ratio
			var ratio = options.startheight/options.startwidth;
			
			//Gather browser and current image size
			var imagewidth = $(this).width();
			var imageheight = $(this).height();
			var browserwidth = $(window).width();
			var browserheight = $(window).height();
			var offset;

			//Resize image to proper ratio
			if ((browserheight/browserwidth) > ratio){
			    $(this).height(browserheight);
			    $(this).width(browserheight / ratio);
			    $(this).children().height(browserheight);
			    $(this).children().width(browserheight / ratio);
			} else {
			    $(this).width(browserwidth);
			    $(this).height(browserwidth * ratio);
			    $(this).children().width(browserwidth);
			    $(this).children().height(browserwidth * ratio);
			}
			if (options.vertical_center == 1){
				$(this).children().css('left', (browserwidth - $(this).width())/2);
				$(this).children().css('top', (browserheight - $(this).height())/2);
			}
			return false;
		});
	};
	
	$.fn.supersized.defaults = { 
			startwidth: 4,  
			startheight: 3,
			vertical_center: 1,
			slideshow: 1,
			navigation:1,
			transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
			pause_hover: 0,
			slide_counter: 1,
			slide_captions: 1,
			slide_interval: 5000
	};

})(jQuery);



(function($){

	$.fn.specialsAutoSlide = function() {
		$.inAnimation = false;
		$.paused = false;
		var options = $.extend($.fn.specialsAutoSlide.defaults, $.fn.specialsAutoSlide.options);
		
		$('#slidecounter .slidenumber').html(1);
	    $('#slidecounter .totalslides').html($("#specialsGroup #specialSlideContents").length);
		
		if (options.slide_captions == 1) {
				var $specialsSlide = $('#specialsGroup #specialSlideContents').eq(0);
				$('#specialsSlideThumb img').attr('src', $specialsSlide.attr('thumb'));
				$('#specialsSlideHeader').html($specialsSlide.attr('header'));
				$('#specialsSlideDescription').html($specialsSlide.attr('description'));
				$('#specialsSlideLink a').html($specialsSlide.attr('linkText'));
				$('#specialsSlideLink a').attr('href', $specialsSlide.attr('link'));
			}

	
		$(window).bind("load", function(){
			//load initial special
			if (options.navigation == 0) $('#navigation').hide();
			//Slideshow
			if (options.slideshow == 1){
				//if (options.slide_counter == 1){ //Initiate slide counter if active
	    		//}
				slideshow_interval = setInterval("nextspecial()", options.slide_interval);
				if (options.navigation == 1){ //Skip if no navigation
					$('#navigation a').click(function(){  
   						$(this).blur();  
   						return false;  
   					}); 	
					//Slide Navigation
				    $('#nextslide').click(function() {
				    	if($.paused) return false; if($.inAnimation) return false;
					    clearInterval(slideshow_interval);
					    nextspecial();
					    slideshow_interval = setInterval(nextspecial, options.slide_interval);
					    return false;
				    });
				    $('#prevslide').click(function() {
				    	if($.paused) return false; if($.inAnimation) return false;
				        clearInterval(slideshow_interval);
				        prevspecial();
				        slideshow_interval = setInterval(nextspecial, options.slide_interval);
				        return false;
				    });
					$('#nextslide img').hover(function() {
						if($.paused == true) return false;
					   	$(this).attr("src", "/SiteBase/wrap/theme0/images/specials_icon_forward_on.png");
					}, function(){
						if($.paused == true) return false;
					    $(this).attr("src", "/SiteBase/wrap/theme0/images/specials_icon_forward_off.png");
					});
					$('#prevslide img').hover(function() {
						if($.paused == true) return false; 
					    $(this).attr("src", "/SiteBase/wrap/theme0/images/specials_icon_back_on.png");
					}, function(){
						if($.paused == true) return false;
					    $(this).attr("src", "/SiteBase/wrap/theme0/images/specials_icon_back_off.png");
					});
					
				    //Play/Pause Button
				    $('#pauseplay').click(function() {
				    	if($.inAnimation) return false;
				    	var src = ($(this).find('img').attr("src") === "/SiteBase/wrap/theme0/images/specials_icon_play_on.png") ? "/SiteBase/wrap/theme0/images/specials_icon_pause_on.png" : "/SiteBase/wrap/theme0/images/specials_icon_play_on.png";
      					if (src == "/SiteBase/wrap/theme0/images/specials_icon_pause_on.png"){
      						$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_play_on.png");
      						$.paused = false;
					        slideshow_interval = setInterval(nextspecial, options.slide_interval);  
				        }else{
				        	$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_pause_on.png");
				        	clearInterval(slideshow_interval);
				        	$.paused = true;
				        }
      					$(this).find('img').attr("src", src);
					    return false;
				    });
				    $('#pauseplay').mouseover(function() {
				    	var imagecheck = ($(this).find('img').attr("src") === "/SiteBase/wrap/theme0/images/specials_icon_play_off.png");
				    	if (imagecheck){
      						$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_play_on.png"); 
				        }else{
				        	$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_pause_on.png");
				        }
				    });
				    
				    $('#pauseplay').mouseout(function() {
				    	var imagecheck = ($(this).find('img').attr("src") === "/SiteBase/wrap/theme0/images/specials_icon_play_on.png");
				    	if (imagecheck){
      						$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_play_off.png"); 
				        }else{
				        	$(this).find('img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_pause_off.png");
				        }
				        return false;
				    });
				}
			}
		});
				
		//Pause when hover on image
		//$('#supersize > *').hover(function() {
		// pause when the spcecials table is hovered over
		$('#tblSpecials').hover(function() {
	   		if (options.slideshow == 1 && options.pause_hover == 1){
	   			if(!($.paused) && options.navigation == 1){
	   				$('#pauseplay > img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_pause_on.png"); 
	   				clearInterval(slideshow_interval);
	   			}
	   		}
	   	}, function() {
			if (options.slideshow == 1 && options.pause_hover == 1){
				if(!($.paused) && options.navigation == 1){
					$('#pauseplay > img').attr("src", "/SiteBase/wrap/theme0/images/specials_icon_pause_off.png");
					slideshow_interval = setInterval(nextslide, options.slide_interval);
				} 
			}
		});
		
	};
	
	$.fn.specialsAutoSlide.defaults = { 
			slideshow: 1,
			navigation:1,
			transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
			pause_hover: 0,
			slide_counter: 1,
			slide_captions: 1,
			slide_interval: 5000
	};

	
})(jQuery);


	//Slideshow Next Slide
	function nextslide() {
		//see if photo gallery or vido gallery is displayed
		if ($("#gallery").css('display')=="block" ||
			$("div[id^='video'][class='simple_overlay'][style*='block']").length>0){
			//if yes the don't show next slide
			return false;
		}
		if($.inAnimation) return false;
		else $.inAnimation = true;
	    var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
	    var currentslide = $('#supersize .activeslide');
	    currentslide.removeClass('activeslide');
		
	    if ( currentslide.length == 0 ) currentslide = $('#supersize a:last');
			
	    var nextslide =  currentslide.next().length ? currentslide.next() : $('#supersize a:first');
	    var prevslide =  nextslide.prev().length ? nextslide.prev() : $('#supersize a:last');
		
		
		//Display slide counter
		var slidecount = $('#slidecounter .slidenumber').html();
		currentslide.next().length ? slidecount++ : slidecount = 1;
		if (options.slide_counter == 1){
		    $('#slidecounter .slidenumber').html(slidecount);
		}
		
		$('.prevslide').removeClass('prevslide');
		prevslide.addClass('prevslide');
		
		//Captions require img in <a>
	    if (options.slide_captions == 1) {
			var $specialsSlide = $('#specialsGroup #specialSlideContents').eq(slidecount-1);
			$('#specialsSlideThumb img').attr('src', $specialsSlide.attr('thumb'));
			$('#specialsSlideHeader').html($specialsSlide.attr('header'));
			$('#specialsSlideDescription').html($specialsSlide.attr('description'));
			$('#specialsSlideLink a').html($specialsSlide.attr('linkText'));
			$('#specialsSlideLink a').attr('href', $specialsSlide.attr('link'));
		}
	    
	    nextslide.hide().addClass('activeslide')
	    	if (options.transition == 0){
	    		nextslide.show(); $.inAnimation = false;
	    	}
	    	if (options.transition == 1){
	    		nextslide.fadeIn(iFadeInTransitionTime, function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 2){
	    		nextslide.show("slide", { direction: "up" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 3){
	    		nextslide.show("slide", { direction: "right" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 4){
	    		nextslide.show("slide", { direction: "down" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 5){
	    		nextslide.show("slide", { direction: "left" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	
	    $('#supersize').resizenow();//Fix for resize mid-transition
	    
	}
	
	//Slideshow Previous Slide
	function prevslide() {
		if($.inAnimation) return false;
		else $.inAnimation = true;
	    var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
	    var currentslide = $('#supersize .activeslide');
	    currentslide.removeClass('activeslide');
		
	    if ( currentslide.length == 0 ) currentslide = $('#supersize a:first');
			
	    var nextslide =  currentslide.prev().length ? currentslide.prev() : $('#supersize a:last');
	    var prevslide =  nextslide.next().length ? nextslide.next() : $('#supersize a:first');
		
		//Display slide counter
		var slidecount = $('#slidecounter .slidenumber').html();
		currentslide.prev().length ? slidecount-- : slidecount = $("#supersize > *").size();
		if (options.slide_counter == 1){
		    $('#slidecounter .slidenumber').html(slidecount);
		}
		
		$('.prevslide').removeClass('prevslide');
		prevslide.addClass('prevslide');
		
		//Captions require img in <a>
		//Captions require img in <a>
	    if (options.slide_captions == 1) {
			var $specialsSlide = $('#specialsGroup #specialSlideContents').eq(slidecount-1);
			$('#specialsSlideThumb img').attr('src', $specialsSlide.attr('thumb'));
			$('#specialsSlideHeader').html($specialsSlide.attr('header'));
			$('#specialsSlideDescription').html($specialsSlide.attr('description'));
			$('#specialsSlideLink a').html($specialsSlide.attr('linkText'));
			$('#specialsSlideLink a').attr('href', $specialsSlide.attr('link'));
		}
	    
		
	    nextslide.hide().addClass('activeslide')
	    	if (options.transition == 0){
	    		nextslide.show(); $.inAnimation = false;
	    	}
	    	if (options.transition == 1){
	    		nextslide.fadeIn(iFadeInTransitionTime, function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 2){
	    		nextslide.show("slide", { direction: "down" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 3){
	    		nextslide.show("slide", { direction: "left" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 4){
	    		nextslide.show("slide", { direction: "up" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	if (options.transition == 5){
	    		nextslide.show("slide", { direction: "right" }, 'slow', function(){$.inAnimation = false;});
	    	}
	    	
	    	$('#supersize').resizenow();//Fix for resize mid-transition
	}
	
	//Slide Next Special
	function nextspecial() {
		var options = $.extend($.fn.specialsAutoSlide.defaults, $.fn.specialsAutoSlide.options);
		var intNumOfSlides = parseInt($('#specialsGroup #specialSlideContents').length)
	   
		//Display slide counter
		var slidecount = parseInt($('#slidecounter .slidenumber').html());
		slidecount+1<=intNumOfSlides ? slidecount++ : slidecount = 1;
		if (options.slide_counter == 1){
		    $('#slidecounter .slidenumber').html(slidecount);
		}
		
		//Captions require img in <a>
	    if (options.slide_captions == 1) {
			var $specialsSlide = $('#specialsGroup #specialSlideContents').eq(slidecount-1);
			$('#specialsSlideThumb img').attr('src', $specialsSlide.attr('thumb'));
			$('#specialsSlideHeader').html($specialsSlide.attr('header'));
			$('#specialsSlideDescription').html($specialsSlide.attr('description'));
			$('#specialsSlideLink a').html($specialsSlide.attr('linkText'));
			$('#specialsSlideLink a').attr('href', $specialsSlide.attr('link'));
		}
	    
	}
	
	//Slide Previous Special
	function prevspecial() {
		var options = $.extend($.fn.specialsAutoSlide.defaults, $.fn.specialsAutoSlide.options);
	    var intNumOfSlides = parseInt($('#specialsGroup #specialSlideContents').length)
	   
		//Display slide counter
		var slidecount = parseInt($('#slidecounter .slidenumber').html());
		slidecount-1>0 ? slidecount-- : slidecount = intNumOfSlides;
		if (options.slide_counter == 1){
		    $('#slidecounter .slidenumber').html(slidecount);
		}
		
		//Captions require img in <a>
		//Captions require img in <a>
	    if (options.slide_captions == 1) {
			var $specialsSlide = $('#specialsGroup #specialSlideContents').eq(slidecount-1);
			$('#specialsSlideThumb img').attr('src', $specialsSlide.attr('thumb'));
			$('#specialsSlideHeader').html($specialsSlide.attr('header'));
			$('#specialsSlideDescription').html($specialsSlide.attr('description'));
			$('#specialsSlideLink a').html($specialsSlide.attr('linkText'));
			$('#specialsSlideLink a').attr('href', $specialsSlide.attr('link'));
		}
	    
		
	}
	

