
/*
jQuery(document).ready(function() {
    if(jQuery("#movFlashCore").size()>0){
        jQuery(".gBodyContainer").css("background-image","none");
    }
});
*/

var futureVideoData = [];
var futureTerser = null;
function imgOn(oImg)
{
   var strOn  = "_on"    // image to be used with mouse over
   var strOff = "_off"     // normal image
   var strImg = oImg.src
   if (strImg && strImg.indexOf(strOff) != -1) 
      oImg.src = strImg.replace(strOff,strOn)
}

function imgOff(oImg)
{
	var strOn  = "_on";    // image to be used with mouse over
	var strOff = "_off";     // normal image
	var strImg = oImg.src;
	if (strImg && strImg.indexOf(strOn) != -1)
		oImg.src = strImg.replace(strOn,strOff);
}

function preLoadImages(source)
{
	if (document.images)
    {
      preload_image_object = new Image();
	  preload_image_object.src=source;
    }
}

function showDisclaimer(whichDisclaimer) {
	showFlashDisclaimer('disclaimer-' + imgArray[imgIndex][storyName] + '-' + whichDisclaimer, $('pca'), 600, 220);
}

function showFlashDisclaimer( obj, anchor, x, y){
	if(typeof onopen == 'function') { onopen(anchor,obj) }

	hideDhtmlPop()

	obj=document.getElementById(obj)
	if (obj==null) return;
	obj.style.visibility='hidden'
	obj.style.display='inline'

	_currentDhtmlPop=obj

	obj.style.left = (x) + 'px';
	obj.style.top  = (y) + 'px';
	obj.style.visibility='visible'

	if(typeof cleanupPop == 'function'){cleanupPop()}
}

function clearScrollFlag() {
  bScrolling = false;
}

//New stuff
function loadFutureVideo(videoDataIndex) {
	var index = null;
	
	if(typeof(videoDataIndex) === 'number') {
		index = videoDataIndex;
	} else {
		for(var i = 0;i < futureVideoData.length; i++) {
			if(futureVideoData[i].videoData && futureVideoData[i].videoData.flvSrc === videoDataIndex) {
				index = i;
				break;
			}
		}
	}
	
	futureTerser = new Terser({
        name: "futureTerser",
        shell: "/apps/nna/docroot/swf/videoPlayer_CMS.swf",
        element: "#video-swf",
        id:  "video"+(jQuery.flash ? "" : "_swf"),
        height: 361,
        width: 712,
        params: {
            wmode: "transparent"
        },
        edit: cqEditAny
    });
	futureTerser.queue();
	futureTerser.extend(futureVideoData[index]);
	
	showBGOverlay();
	showDhtmlPop('video-popup','event',this,'centerinwindow',popupVideo);
}
function closeFutureVideo() {
	hideBGOverlay();
}
function showBGOverlay(){
	// mask body
	var obj = $('fadeBody');
	if (obj) {
		obj.style.display='inline';
		obj.style.visibility='visible';
	}
}

function hideBGOverlay(){
	obj=$('fadeBody');
	if (obj) {
		obj.style.visibility='hidden';
		obj.style.display='none';
	}
}
/* Multiple Galleries JS */

FV = {};
FV.runningVars = {};

FV.Galleries = function(options) {
	this.options = {};
	jQuery.extend(true, this.options, options);
	//tracking vars
	this.imageNum = 1;
	// initialize functions
	this.initializeThumbs();
	this.initializeLarge();
	this.initializePopUp();
	this.initializeVideoButtons();
	
	
}
// Handles the rollover effect for the thumbnails since IE6 doesn't support :hover on divs.
FV.Galleries.prototype.initializeThumbs = function() {
	var self = this;
	var galleries = jQuery('.gallery-container');	
	galleries.each(function(index, item){	
		var thumbs = jQuery(item).find('.thumbnail');
		jQuery(thumbs).each(function(index, item) {
			
			
				jQuery(item).children('.static').bind('mouseenter', function(e){
					if (jQuery(this).parents('.thumbnail').hasClass('active')) {} else {
						jQuery(this).css('display', 'none');
						jQuery(this).siblings('.hover').css('display', 'block');
					}
				});
				jQuery(item).children('.hover').bind('mouseleave', function(e){
					if (jQuery(this).parents('.thumbnail').hasClass('active')) {} else {
						jQuery(this).css('display', 'none');
						jQuery(this).siblings('.static').css('display', 'block');
					}
				});
			
		});
	});
	
	
}

//intializes the update to the large image above the thumbs with the image referenced in the link around the thumbnail when clicked
FV.Galleries.prototype.initializeLarge = function() {
	var thumbLinks = jQuery('a.update-lrg');
	var self = this;
	thumbLinks.each(function(index, item){
		
		jQuery(item).bind('click', function(e) {
			if(jQuery(this).parents('.thumbnail').hasClass('active')) {
				e.preventDefault();
			} else {
				e.preventDefault();
				self.imageNum = jQuery(this).attr('rel');
				var trackingData = {
						num: self.imageNum,
						vehicle: jQuery(this).parents('.gallery-container').attr('id')
				}
				crmEvent4(trackingData);
				var imgRef = jQuery(this).attr('href');
				var imgLink = jQuery(this).attr('target');
				var largerImg = jQuery(item).parents('.gallery-container').children('.display-img');
				var allThumbs = jQuery(this).parents('.thumbnail').siblings('.thumbnail');
				jQuery(largerImg).find('.pop-img').attr('href', imgLink);
				jQuery(largerImg).find('img.large-img').attr('src', imgRef);
				allThumbs.removeClass('active');
				allThumbs.children('.hover').css('display','none');
				allThumbs.children('.static').css('display','block');
				jQuery(this).parents('.thumbnail').addClass('active');
			}
			
		});
	});
	
}
// when you click the large Image pop up teh detail image
FV.Galleries.prototype.initializePopUp = function(){
	var self = this;
	var detailClose = jQuery('.detail-close');
	var largeImgPop = jQuery('.pop-img');
	var detailImg = jQuery('.detail-img img');
	var detailContainer = jQuery('#detailPopupContainer');
	var fadeBG = jQuery('#fadeBody');
	detailClose.bind('click', function(e){
		e.preventDefault();
		detailContainer.hide();
		fadeBG.hide();
		detailImg.attr('src',"");
	});
	
	 largeImgPop.each(function(index, item) {
		 jQuery(item).bind('click', function(e) {
			 e.preventDefault();
			 
			 var trackingData = {
				 num:  self.imageNum,
				 vehicle: jQuery(this).parents('.gallery-container').attr('id')
			 };
			 crmEvent5(trackingData);
			 detailImg.attr('src', jQuery(this).attr('href'));
			 detailContainer.fadeIn(1100);
			 fadeBG.fadeIn(400,function(){
			 	fadeBG.css('visibility','visible');
			 });
		 });		 
	 });
}

FV.Galleries.prototype.initializeVideoButtons = function() {
	jQuery('.future-button').each(function(i, button) {
		
		jQuery(button).click(function(e) {
			e.preventDefault();
			var video = jQuery(this).attr('href');
			loadFutureVideo(video);
		});
	
});
	
}


jQuery(document).ready(function(){
	jQuery("#fadeBody").fadeTo(1, 0.8);
	
	//Force FadeBody to be full mainContainer height
	var tHeight = jQuery('.mainContainer').css('height');
	jQuery("#fadeBody").css('height',tHeight);
	
	jQuery('#video-popup .gClose').click(function(e) { 
		closeFutureVideo();
	});
	
	
	
	var options= {};
	FV.runningVars.Galleries = new FV.Galleries(options);
	
});




