/* Standard JS for site */

$(document).ready(function() 
    {
			
		/* check for iPhone */
    	var agent=navigator.userAgent.toLowerCase();
		var is_iphone = ((agent.indexOf('iphone')!=-1));
		
		var is_ios = (/iphone|ipod|ipad/i).test(agent);		
		
		if (is_iphone) {
		
			/* iPhone telephone number formatting */
			/* adds 'tel:' schema formatted phone number to all microformatted telephone number on the page */
			$('.tel .value:not(.nodial)').each(function(){
				var telNo = $(this).text().replace(/\(.*\)/,'').replace(/\s+/g,'');
				var wrapLink = '<a href="tel:'+telNo+'"></a>';
				$(this).wrap(wrapLink);
			});
		
		}
		
	
	
	
		// add '?gallery' to each of the thumbnail links, then add the fancybox functionality to them
		$("#galleryThumbs a, #specThumbs a").attr({href: function() {return this.href + '?gallery'}}).fancybox({
			'overlayShow':	true,
			'overlayOpacity': 0.8,
			'hideOnContentClick': true
		});
	
	
	
			
	
		// transcript
		$('.showTranscript, .hideTranscript').show();
		$('.transcript').hide();
		
		$('.showTranscript').click(function() {
			$('.transcript').slideToggle();
			$('.showTranscript').hide();
		});
		
		$('.hideTranscript').click(function() {
			$('.transcript').slideToggle(function(){
				$('.showTranscript').show();
			});
			
		});
		
		
		
		
		// Video
			
		if ( !is_ios ) {
			$('.videoTriggerLink').each(function() {
				var thisId = $(this).attr('id');
				thisId = thisId.replace('TriggerLink','');
				$(this).attr('href','#'+thisId);
			});
			
			
			$("a#mi4MakingClipTriggerLink").fancybox({
				'titleShow'		: false,
				'frameWidth': 560,
				'frameHeight': 315,
				'overlayShow': true,
				'overlayOpacity': 0.8,
				'transitionIn': 'elastic',
				'transitionOut': 'elastic'
			});
		}
		
		
	   	var flashvars = {autoplay: "true", fs: "true"}; 
		var params = {allowfullscreen: "true", wmode: "transparent"}; 
		var attributes = {};
		
		swfobject.embedSWF("http://www.youtube.com/v/CCuxnofBIKI?version=3&amp;hl=en_US&amp;rel=0", "videoObjectmi4MakingClip", "560", "315", "9.0.0", false, flashvars, params, attributes);


    } 
);

