//Omniture Variable Declarations		
		
var shareType='';
var videoIdx='';

(function($){
	$.musa_zoom_gallery={
		
		_init:function(){			
			$.musa_zoom_gallery.displayVideo('1');					
		},
		displayVideo:function(zoomId){		
			
			var flashPath=zoomFlashPath;
			if(zoomId==1) flashPath=zoomFirstFlashPath;
				
			$('#flashcontent').html('<a href=\"http://get.adobe.com/flashplayer/\"><img src=\"images/vehicles/gallery/downloadFlash_reveal.jpg\" width=\"750\" height=\"319\" border=\"0\" alt=\"\"  /></a>');
			$('#flashcontent').flash({ 
				swf: flashPath + "p_zoomZoom_video" + zoomId + "_base.swf",
				height:  280, 
				width: 520, 
				params: { 
					play: true,
					base: flashPath,
					wmode: 'transparent',
					scale: 'noscale',
					name: 'bod',
					quality:'high',
					align: '',
					bgcolor:'#fff',
					flashvars: { 
						assetURL: assetPath, 
						streamingUrl:streamingPath, 
						applicationUrl: applicationPath
					} 
				} 
			});
			
			$('#flashcontent').show();
			
		}
	}	
	$.musa_zoom_gallery._init();
})(jQuery);

function zoomFlashWrite(zoomId) { $.musa_zoom_gallery.displayVideo(zoomId); }





$(document).ready(function() {
	// invoke the code formerly known as "the awesome"
	//$("#shareholder").social({type:'photo', item:'remote'});
	$("div.videoshare").social({type:'video', item:'remote'});
});

$(window).bind("beforeunload", function(){
		
	// pass vehicleCode to Social KMU popup
   	vehCode = vehCode.toUpperCase();
	vehURL = "/MusaWeb/displaySocialHandraiser.action?vehicleCode="+ vehCode;
	
	// If user shared and didn't see pop up before it has been displayed
	if(($.cookie('shared')) && (!$.cookie('socialMediaKMUSubmitted'))){
		//$.cookie('socialMediaKMUSubmitted', true, { expires: 30 });
		window.open(vehURL,'KMUPopup','width=550,height=375,scrollbars=yes');
	}

});





(function($){
	
	/*	
	*	$.fn.social // Inserts Social share menu
	*	
	*	Receives:
	*		type	shareable type, defaults to photo 
	*		item	shareable source to be shared, defaults to actual.
	*				if remote finds related file at flick by call to XML.
	**/
	
	$.fn.social = function(options){     
		
		var defaults = {  
			type: 'photo', // photo, photoSet, video, videoGallery
			item: 'actual' // actual, remote
		};  
		var options = $.extend(defaults, options);
		
		// List of supported networks
		var shareNetworks = '<div class="sharefloat"><ul class="shareNetworks" style="z-index: 1000; background-color: #fff;">'+
					'<li><div class="shareIcon url">&nbsp;</div>'+
					'<div class="pitf" onclick="$.fn.social.share(\'url\', \''+options.type+'\', \''+options.item+'\');">Copy URL</div></li>'+
					'<li><div class="shareIcon facebook">&nbsp;</div>'+
					' <div class="pitf" onclick="$.fn.social.share(\'facebook\', \''+options.type+'\', \''+options.item+'\');">Facebook</div></li>'+
					'<li><div class="shareIcon myspace">&nbsp;</div>'+
					' <div class="pitf" onclick="$.fn.social.share(\'myspace\', \''+options.type+'\', \''+options.item+'\');">My Space</div></li>'+
					'<li><div class="shareIcon digg">&nbsp;</div>'+
					' <div class="pitf" onclick="$.fn.social.share(\'digg\', \''+options.type+'\', \''+options.item+'\');">digg</div></li>'+
					'<li><div class="shareIcon delicious">&nbsp;</div>'+
					' <div class="pitf" onclick="$.fn.social.share(\'delicious\', \''+options.type+'\', \''+options.item+'\');">del.icio.us</div></li>'+
					'<li><div class="shareIcon twitter">&nbsp;</div>'+
					' <div class="pitf" onclick="$.fn.social.share(\'twitter\', \''+options.type+'\', \''+options.item+'\');">Twitter</div></li>';
			// no Flicker sharing for videos
			if((options.type == 'photo') || (options.type == 'photoSet')){
				shareNetworks +='<li><div class="shareIcon flickr">&nbsp;</div>'+
					' <div class="pitf" onclick="$.fn.social.share(\'flickr\', \''+options.type+'\', \''+options.item+'\');">Flickr</div></li>';
			}
			shareNetworks +='</ul></div>'
		
		// Sets different type of menus for each type of asset
		switch(options.type){
			case 'photo':
				var shareMenu =	'<div class="shareMenuPhoto">'+
					'<ul class="shareTag">'+
					'<li>'+
					'<div class="tagTitle">SHARE THIS IMAGE</div>'+
					shareNetworks+
					'</li></ul></div><div class="spacer" style="clear: both;"></div>'+
					'<!-- End of .shareMenu -->';
				break;
			case 'photoSet':
				var shareMenu =	'<div class="shareMenuSet">'+
					'<ul class="shareTag">'+
					'<li>'+
					'<div class="tagTitle"><a href="javascript:void(0)">Share this Slideshow</a></div>'+
					shareNetworks+
					'</li></ul></div><div class="spacer" style="clear: both;"></div>'+
					'<!-- End of .shareMenu -->';
				break;
			case 'video':
				var shareMenu =	'<div class="shareMenuVideo">'+
					'<ul class="shareTag">'+
					'<li>'+
					'<div class="tagTitle">&nbsp;Share this Video</div>'+
					shareNetworks+
					'</li></ul></div><div class="spacer" style="clear: both;"></div>'+
					'<!-- End of .shareMenu -->';
				break;
			case 'videoGallery':
				var shareMenu =	'<div class="shareMenuSet">'+
					'<ul class="shareTag">'+
					'<li>'+
					'<div class="tagTitle"><img src="musa2/images/garage/gallery/social/share_video_gallery.gif"/></div>'+
					shareNetworks+
					'</li></ul></div><div class="spacer" style="clear: both;"></div>'+
					'<!-- End of .shareMenu -->';
				break;
		}

		
		// Inserts corresponding menu to each element matched by selector
		return this.each(function(){
			
			switch(options.type){
				case 'photo':
					
					$(this).html(shareMenu);
					var thisMenu = $(this).find(".shareMenuPhoto");
					break;
					
				case 'photoSet':
					$(this).before(shareMenu);
					var thisMenu = $(this).parent().find(".shareMenuSet");
					break;
					
				case 'video':
					$(this).html(shareMenu);
					var thisMenu = $(this).find(".shareMenuVideo");
					break;
					
				case 'videoGallery':
					$(this).before(shareMenu);
					var thisMenu = $(this).parent().find(".shareMenuSet");
					break;
			}
			
			// Binds mouseover / mouseout behaviour to this menu
			thisMenu.bind("mouseover mouseout", function(){
				
        		if($(".shareNetworks", thisMenu).css('display') == 'block'){
					$(".shareNetworks", thisMenu).css('display', 'none');
				}else{
					$(".shareNetworks", thisMenu).css('display', 'block');
					// In case it is a video we keep track of which is the one being shared
					if(options.type == 'video'){
						currAsset = thisMenu.parent().parent().find('.videoshare').attr('remote');
						currTitle=thisMenu.parent().parent().find('.videoshare').attr('title');
						videoIdx=thisMenu.parent().parent().find('.videoshare').attr('id');
					}
					if(options.type == 'videoGallery'){
						currAsset = thisMenu.parent().find('h2').attr('playlist');
					}
				}
    		});
			
		});

	}; 
	
	
	/*	
	*	$.fn.social.share // Opens sharing popup
	*	
	*	Receives:
	*
	*		service		where assets are going to be shared
	*		type		shareable type, defaults to photo 
	*		item		source of asset to be shared, defaults to "actual".
	*					if "remote" looks for corresponding remote file.
	**/
	
	$.fn.social.share = function(service, type, item){ 
	
		var title = currTitle;
		var winFeatures = 'width=750,height=500,scrollbars=1';
		var assetURL;
		var embed;
		var tweet;
		var flickrURL;
	
		// if user shares, track it for the popup
		$.cookie('shared', true, { expires: 30 });

		// Sets actual or remote assetURL
		switch(type){
			case 'photo':
				// We are sharing a remote asset
				if(item != 'actual'){
					assetURL = currAsset;
				// We are sharing the actual file
				}else{
					assetURL = $('#imageDisplay img.bigPhoto').attr('src');
				}
				embed = '<img src="'+assetURL+'" alt="'+title+'" />';
				tweet = title+' '+assetURL;
				flickrURL = flickrImg;
				
				break;
			
			case 'photoSet':
				assetURL = $('.thumbs.active h2').attr('set');
				embed = '<a href="'+assetURL+'" target="_blank"><img width="200" src="'+$('.thumbs.active ul.clearfix li:first a img').attr('remote')+'" alt="'+title+' gallery" /><br />'+title+' gallery</a>';
				tweet = title+' gallery '+assetURL;
				flickrURL = $('.thumbs.active h2').attr('collection');
				break;

			case 'video':
				assetURL = 'http://www.youtube.com/watch?v='+currAsset;
				embed = '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/'+currAsset+'&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+currAsset+'&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';
				tweet = title+' http://www.youtube.com/watch?v='+currAsset;
				flickrURL = $('.thumbs:first h2').attr('collection');
				break;
			
			case 'videoGallery':
				assetURL = 'http://www.youtube.com/view_play_list?p='+currAsset;
				embed = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/p/'+currAsset+'&hl=es&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/p/'+currAsset+'&hl=es&fs=1" type="application/x-shockwave-flash" width="480" height="385" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
				tweet = title+' http://www.youtube.com/view_play_list?p='+currAsset;
				flickrURL = $('.thumbs:first h2').attr('collection');
				break;
		}
		
		// Pops up sharing window
		switch(service) {
			case 'url':
				prompt('Copy and paste this code into your own website or blog', embed);
				break;
			case 'facebook':
				open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(assetURL)+'&t='+encodeURIComponent(title),'Facebook',winFeatures);			
				shareType='facebook';
				break;
			case 'myspace':
				open('http://www.myspace.com/Modules/PostTo/Pages/?t='+encodeURIComponent(title)+'&c=&u='+encodeURIComponent(assetURL)+'&l=4','MySpace',winFeatures);
				shareType='myspace';
				break;	
			case 'digg':
				open('http://digg.com/submit?url='+encodeURIComponent(assetURL)+'&title='+encodeURIComponent(title)+'&media=image&topic=autos','Digg',winFeatures);
				shareType='digg';
				break;				
			case 'delicious':
				open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(assetURL)+'&title='+encodeURIComponent(title),'Delicious',winFeatures);
				shareType='delicious';
				break;
			case 'twitter':
				open('http://twitter.com/home?status='+encodeURIComponent(tweet),'Twitter',winFeatures);
				shareType='twitter';
				break;
			case 'flickr':			
				open(flickrURL,'Flickr',winFeatures);
				break;
			
		}
		
		
		s.linkTrackVars='eVar6,eVar28,events';
			s.events='event10';
			s.eVar6='Share Zoom Zoom Video ' + videoIdx + ' To ' + shareType;
			s.eVar28='Share Zoom Zoom Video ' + videoIdx + ' To ' + shareType;
			s.tl(this,'o','Share Zoom Zoom Video ' + videoIdx + ' To ' + shareType);
			void(s_gi(s_account));

	};
	
})(jQuery);  