/**
2 * @author mazda rmt
3 */
var slidetimer='';
(function($){
	$.musa_ar={
		_init:function(){
			$('a[name=modal]').click(function(e) {   
		        //Cancel the link behavior   
		        e.preventDefault();   
		        //Get the A tag   
		        var id = $(this).attr('href');   
				
				if(id=="#dialog2"){				
					$('#dialog2').flash({ 
						swf: 'musa2/flash/garage/upcoming/mz2/microsite/swf/videoPlayer.swf', 
						height:  405, 
						width: 606, 
						flashvars: { 
							video: '../video/mazda2AR.flv'
						}, 
						params: { 
							menu:false,
							play: true,
							allowFullScreen:true,
							//base: movieBase,
							//wmode: 'transparent',
							quality:'high',
							align: '',
							//bgcolor:'#fff',
							attributes: {
								id:'video',
								name:'video'							
							}
						} 
					});					
				}
				
				
		        //Get the screen height and width   
		        var maskHeight = $(document).height();   
		        var maskWidth = $(window).width();   
		       
		        //Set height and width to mask to fill up the whole screen   
		        $('#mask').css({'width':maskWidth,'height':maskHeight});   
		           
		        //transition effect        
		        $('#mask').fadeIn(1000);       
		        $('#mask').fadeTo("slow",0.8);     
		       
		        //Get the window height and width   
		        var winH = $(window).height();   
		        var winW = $(window).width();   
		                 
		        //Set the popup window to center   
		        $(id).css('top',  100);   
		        $(id).css('left', winW/2-$(id).width()/2);   
		       
		        //transition effect   
		        $(id).fadeIn(500);    
		       
		    });   
		       
		    //if close button is clicked   
		    $('.window .close').click(function (e) {   
		        //Cancel the link behavior   
		        e.preventDefault();  
				$.musa_ar.closeOverlay(); 
		          
		    });        
		       
		    //if mask is clicked   
		    $('#mask').click(function () {   
		        $(this).hide();   
		        $('.window').hide();   
		    });		
		},
		
		closeOverlay:function(){
			$('#mask, .window').hide();
		},
			
		slideout:function(){
			$("div.shareiconholder a, div.shareiconholder div").animate({ 
		        left:0
		      }, 1500 );

		},
		
		slidein:function(){
			$("div.shareiconholder a, div.shareiconholder div").animate({ 
		        left:-196
		      }, 1500 );

		},
		
		popNavItem: function(url) {
			var winFeatures = 'width=599,height=417,scrollbars=0';
			open(url,'NavLink',winFeatures);			
					
		},
		
		shareLink:function(service, imgURL, titlename) {
			var winFeatures = 'width=750,height=500,scrollbars=1';
			var assetURL;
			var embed;
			var tweet;
			var flickrURL;
			var title = '2011 MAZDA2';
			if(titlename) title=titlename;
			if(imgURL) {
				assetURL = imgURL;
				flickrURL = imgURL;
			}
			else assetURL = 'http://'+document.domain+'/MusaWeb/MAZDA2.action';
			
			if(imgURL) embed = imgURL;
			else embed = 'http://'+document.domain+'/MusaWeb/MAZDA2.action';
			if(imgURL) tweet = title+' '+imgURL;
			else tweet = title+' '+'http://'+document.domain+'/MusaWeb/MAZDA2.action';
			var pageURL = document.URL;
			
			//Omniture Variable Declarations		
			var shareId='';
			var shareType='';
			var linkIdx='';
			
			
			switch(service) {
				case 'facebook':
					linkIdx="Facebook";
					open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(assetURL)+'&t='+encodeURIComponent(title),'Facebook',winFeatures);			
					break;
				case 'myspace':
					linkIdx="MySpace";
					open('http://www.myspace.com/Modules/PostTo/Pages/?t='+encodeURIComponent(title)+'&c=&u='+encodeURIComponent(assetURL)+'&l=4','MySpace',winFeatures);
					break;	
				case 'digg':
					linkIdx="Digg";
					open('http://digg.com/submit?url='+encodeURIComponent(assetURL)+'&title='+encodeURIComponent(title)+'&media=image&topic=autos','Digg',winFeatures);
					break;				
				case 'delicious':
					linkIdx="Delicious";
					open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(assetURL)+'&title='+encodeURIComponent(title),'Delicious',winFeatures);
					break;
				case 'twitter':
					linkIdx="Twitter";
					open('http://twitter.com/home?status='+encodeURIComponent(tweet),'Twitter',winFeatures);
					break;
				case 'flickr':			
					linkIdx="Flickr";
					open(flickrURL,'Flickr',winFeatures);
					break;
			}
			//Concatenate Variables and Fire Omniture(upgraded to h-code with scr07538)
		
			shareId="Share Mazda2 on MUSA to " + linkIdx + "- MZ2";
			//if(shareType!="Slideshow") shareId += " " + assetIdx;
			s_linkTrackVars='eVar6,eVar28,s_events';s_linkName=shareId;s_linkTrackEvents='event10';s_linkType='o';s_eVar6=shareId;s_eVar28=shareId;s_events='event10';
			//s.linkTrackVars='eVar6,eVar28,s_events';s.eVar6=shareId;s.eVar28=shareId;s.events='event10';s.tl(this,'o','share MAZDA2 on MUSA');
		},
		
		shareVideo:function(service, videoUrl, titlename) {
			var winFeatures = 'width=750,height=500,scrollbars=1';
			var assetURL;
			var embed;
			var tweet;
			var flickrURL;
			var title = titlename;
			assetURL = videoURL;
			flickrURL = videoURL;
			embed = imgURL;
			tweet = title+' '+imgURL;
			
			//Omniture Variable Declarations		
			var shareId='';
			var shareType='';
			var linkIdx='';
			
			
			switch(service) {
				case 'facebook':
					linkIdx="Facebook";
					open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(assetURL)+'&t='+encodeURIComponent(title),'Facebook',winFeatures);			
					break;
				case 'myspace':
					linkIdx="MySpace";
					open('http://www.myspace.com/Modules/PostTo/Pages/?t='+encodeURIComponent(title)+'&c=&u='+encodeURIComponent(assetURL)+'&l=4','MySpace',winFeatures);
					break;	
				case 'digg':
					linkIdx="Digg";
					open('http://digg.com/submit?url='+encodeURIComponent(assetURL)+'&title='+encodeURIComponent(title)+'&media=image&topic=autos','Digg',winFeatures);
					break;				
				case 'delicious':
					linkIdx="Delicious";
					open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(assetURL)+'&title='+encodeURIComponent(title),'Delicious',winFeatures);
					break;
				case 'twitter':
					linkIdx="Twitter";
					open('http://twitter.com/home?status='+encodeURIComponent(tweet),'Twitter',winFeatures);
					break;
				case 'flickr':			
					linkIdx="Flickr";
					open(flickrURL,'Flickr',winFeatures);
					break;
			}
			//Concatenate Variables and Fire Omniture
			/*
			shareId="Share Mazda2 on MUSA to " + linkIdx + "- MZ2";
			s_linkTrackVars='eVar6,eVar28,s_events';s_linkName=shareId;s_linkTrackEvents='event10';s_linkType='o';s_eVar6=shareId;s_eVar28=shareId;s_events='event10';
			*/
		}
	}

	$.musa_ar._init();
})(jQuery);

function awesomeslider() {
	$.musa_ar.slideout();
}

function awesomeslideback() {
	slidetimer=setTimeout("$.musa_ar.slidein()",200);
}

function killtimeout() {
	clearTimeout(slidetimer);
}

function shareLink(service, imgURL, titlename) {
	$.musa_ar.shareLink(service, imgURL, titlename);
}

function shareVideo(service, videoURL, titlename) {
	$.musa_ar.shareLink(service, videoURL, titlename);
}

function extCloseOverlay(){
	$.musa_ar.closeOverlay(); 
}

function popNavItem(url){
	$.musa_ar.popNavItem(url); 
}
