﻿/*
 * 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
 */
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:'Next >',PrevElement:'fssPrev',PrevElementText:'< Prev',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);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){jQuery('> *:lt('+(newIndex+1)+')',fssThis).fadeIn(settings.speed);}else if(newIndex<=ActSlide){jQuery('> *:gt('+newIndex+')',fssThis).fadeOut(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="#">'+(i+1)+'<\/a><\/li>';}else{li=li+'<li class="'+settings.ListLi+i+'"><a href="#">'+(i+1)+'<\/a><\/li>';}
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);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;});}
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);}else if(e.which==37){prevSlide=ActSlide+1;stopAutoplay();jumpTo(prevSlide);}else if(e.which==32){if(intval){stopAutoplay();}
else{autoplay();}
return false;}});}
if(settings.autoplay){autoplay();}else{intval=false;}});};

/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.2, 09.03.2009
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Changelog:
 *    09.03.2009 Version 1.2
 *    - Update for jQuery 1.3.x, removed @ from selectors
 *    11.09.2007 Version 1.1
 *    - removed noConflict
 *    - added png-support for input type=image
 *    - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
 *    31.05.2007 initial Version 1.0
 * --------------------------------------------------------------------
 * @example $(function(){$(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready
 *
 * jQuery(function(){jQuery(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready when using noConflict
 *
 * @example $(function(){$('div.examples').pngFix();});
 * @desc Fixes all PNG's within div with class examples
 *
 * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );});
 * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png
 * --------------------------------------------------------------------
 */

(function($) {

jQuery.fn.pngFix = function(settings) {

	// Settings
	settings = jQuery.extend({
		blankgif: 'blank.gif'
	}, settings);

	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {

		//fix images with png-source
		jQuery(this).find("img[src$=.png]").each(function() {

			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}

			jQuery(this).hide();
			jQuery(this).after(strNewHTML);

		});

		// fix css background pngs
		jQuery(this).find("*").each(function(){
			var bgIMG = jQuery(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		});
		
		//fix input with png-source
		jQuery(this).find("input[src$=.png]").each(function() {
			var bgIMG = jQuery(this).attr('src');
			jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', settings.blankgif)
		});
	
	}
	
	return jQuery;

};

})(jQuery);

$(window).load(
 function ()
 {
     $('#header').css('visibility', 'visible'); // show the header now that the window has loaded.
     // banner slides - If JS is enabled, then set all the imgs in slideshow to display.
     $('.masthead').show();

 });

 $(document).ready(function ()
 {
     $(document).pngFix();
     $('#header').css('visibility', 'hidden'); // hide the header until the images are loaded. This hides the flicker as images load.
     $('#slideshow').fadeSlideShow({
         width: 778,
         height: 337,
         PlayPauseElement: false,
         NextElement: false,
         PrevElement: false,
         ListElement: false,
         interval: 10000,
         allowKeyboardCtrl: false
     });
 });
