$(function() {
	pageHasSlideshow=true
	
var ua=$.browser

	//http://www.kyrielles.net/sliderkit/
	$(".homePromo").sliderkit({
						shownavitems:3,
						scroll:1,
						circular:false,
						start:0,
						auto: false
					});


	var screenWidth = ($(window).width() < 1200) ? true : false;
	if(screenWidth) {
   		$("#wrapper").css({"width":"960px"});
  		$(".homeQuote").css({"margin-left":"-100px"});
  		$(".homeQuoteIE").css({"margin-left":"-100px"});
  		$(".homeCTA").css({"margin-left":"-100px"});
  		$(".pHomeCTA").css({"margin-left":"-100px"});
  		$("#slideshow").css({"width":"960px","margin-left":"-480px"});
   		$("#slideshow div").css({"width":"960px"});
   }
	  
  $('#slideshow').after('<div id="heroNav">').cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 10000,
        pager:  '#heroNav',
        after: function() {
	      	   		if(screenWidth) {
	      	   			$("#heroNav").css({"left":"855px"});
	      	   		}
				}
    });
    
$(".homeQuoteIE").textShadow();

//The flip animation doesn't work within the slider kit within IE - no idea why so kill the flip completely. Transition still works.
if ($.browser.msie) {
	$('.promo_referral_front').html('<a href="/specialoffers" class="iePanelLink"></a>');
	$('.promo_ac_front').html('<a href="http://americancoach.com" class="iePanelLink" target="_blank"></a>');
	$('.promo_loyalty_front').html('<a href="/specialoffers" class="iePanelLink"></a>');
	$('.promo_fun_front').html('<a href="/about" class="iePanelLink"></a>');
	$('.promo_mhevent_front').html('<a href="/mhevent" class="iePanelLink"></a>');
	$('.promo_dieselSale_front').html('<a href="/locate" class="iePanelLink"></a>');
	$('.promo_exc_front').html('<a href="/excursion" class="iePanelLink"></a>');

//    $('.flipIt').bind("click",function(){
//    	var elem = $(this);
//		if(elem.data('flipped'))
//		{
//			elem.children('.flipBack').hide();
//			elem.data('flipped',false)
//		} else {
  //  		elem.children('.flipBack').show();
    //		elem.children('.flipBack').bind("click",function() {
//    			$(this).hide();
  //  		});
	//		elem.data('flipped',true);
//		}
 //	});
    stopPTimer();
    
  } else {

	/* The following code is executed once the DOM is loaded */
	
	$('.flipIt').bind("click",function(){
		
		// $(this) point to the clicked .sponsorFlip element (caching it in elem for speed):
		
		var elem = $(this);
		
		// data('flipped') is a flag we set when we flip the element:
		
		if(elem.data('flipped'))
		{
			// If the element has already been flipped, use the revertFlip method
			// defined by the plug-in to revert to the default state automatically:
			
			elem.revertFlip();
			
			// Unsetting the flag:
			elem.data('flipped',false)
		}
		else
		{
			// Using the flip method defined by the plugin:
			
			elem.flip({
				direction:'lr',
				speed: 200,
				onBefore: function(){
					// Insert the contents of the .sponsorData div (hidden from view with display:none)
					// into the clicked .sponsorFlip div before the flipping animation starts:
					
					elem.html(elem.children('.flipBack').html());
				},
				onEnd: stopPTimer()
				
			});
			
			// Setting the flag:
			elem.data('flipped',true);
		}
	});
	
	} //end MSIE

	$(".popUpLink").fancybox({
		'overlayShow'	:	true,
		'transitionIn' : 'fade'
	});


});

function stopP() {
	$('a.flipBackLink').click( function(event) {
       event.stopPropagation();
   });
}

function stopPTimer() {
	var t=setTimeout("stopP()",1000);
}


