function file_get_ext(filename)
{
    return typeof filename != "undefined" ? filename.substring(filename.lastIndexOf(".")+1, filename.length).toLowerCase() : false;
}


jQuery(document).ready(function() {	


	maskOverlay = jQuery("<div>").attr("id","mask");
	jQuery("body").append(maskOverlay);
	jQuery('#mask').css('opacity', '0.5');
	jQuery('#stimuli_bottomNavClose').click(function(e){
		e.preventDefault();
	});
	//select all the a tag with name equal to modal
	jQuery('a[class=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		
		//Get the screen height and width
		var maskHeight = jQuery(document).height()-5;
		var maskWidth = jQuery(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		jQuery('#mask').fadeTo("slow",0.8);	
		
		//Get the A tag
		var id = jQuery(this).attr('href');
		
		var box = jQuery('#QuickTime');
		var box_width = 458;
		var box_height = 422;
		
		var link_id = jQuery(this).attr('rel');
		jQuery('#video').css('height','400px');
		if(file_get_ext(id)=='flv')
		{
			var flash = '<embed src ="/wp-content/plugins/media-gallery/flvplayer.swf?file='+id+'&autostart=true" width="458" height="394" bgcolor="#000000" allowfullscreen="true"/>';
				
			jQuery("#video").html(flash);
		} else if(file_get_ext(id)=='mov') {
			var play_mov = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="394" width="458">';
			play_mov += '<param name="src" value="'+id+'"/>';
			play_mov += '<param name="controller" value="true" />';
			play_mov += '<param name="autoplay" value="true" />';
						
			play_mov += '<param name="scale" value="tofit" />';
			play_mov += '<embed type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" bgcolor="#000000" scale="tofit" height="394" width="458" src="'+id+'" controller="true" autoplay="true" /></object>';
			
			jQuery("#video").html(play_mov);
		} else if(file_get_ext(id)=='mp4') {
			var play_mov = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="394" width="458">';
			play_mov += '<param name="src" value="'+id+'"/>';
			play_mov += '<param name="controller" value="true" />';
			play_mov += '<param name="autoplay" value="true" />';
						
			play_mov += '<param name="scale" value="tofit" />';
			play_mov += '<embed type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" bgcolor="#000000" scale="tofit" height="394" width="458" src="'+id+'" controller="true" autoplay="true" /></object>';
			
			jQuery("#video").html(play_mov);
		} else if(file_get_ext(id)=='mp3'){
			box_height = 62;
			jQuery('#video').css('height','40px');
			var flash = '<embed src ="/wp-content/plugins/media-gallery/flvplayer.swf?file='+id+'&autostart=true" width="458" height="20" bgcolor="#000000" allowfullscreen="true"/>';
				
			jQuery("#video").html(flash);
		} else {
			jQuery("#video").html('<object width="458" height="394" bgcolor="#000000" type="application/x-shockwave-flash" data="http://www.youtube.com/v/'+id+'"><param name="movie" value="http://www.youtube.com/v/'+id+'" />This video was embedded using the YouTuber plugin by <a href="http://www.roytanck.com">Roy Tanck</a>. Adobe Flash Player is required to view the video.</object>');
		}
		
		
		//Get the screen height and width
		var maskHeight = jQuery(document).height()-5;
		var maskWidth = jQuery(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		
		
		//transition effect		
		//jQuery('#mask').fadeIn(1000);	
		jQuery('#mask').fadeTo("slow",0.8);	
		//jQuery('#mask').animation('');
		
		//jQuery('#mask').animate({'opacity':0.75}, 1000);
		
		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
		var scrollTop = jQuery(window).scrollTop();
		
		var boxTop = '403px';//Move the box to under the banner 
		//Set the popup window to center
		jQuery('#QuickTime').css('top',  boxTop);
		jQuery('#QuickTime').css('left', (winW-box_width)/2);
	
		//transition effect
		jQuery('#QuickTime').fadeIn(); 
	
	});
	jQuery('a[id=close]').click(function(e) {		
		jQuery('.window').hide();
		//jQuery('#mask').hide();		
		jQuery('#video *').remove();
		e.preventDefault();
		jQuery('#mask').fadeOut();	
	});
	
	//if close button is clicked
	jQuery('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		jQuery('#video *').remove();
		jQuery('#mask').fadeOut();
		jQuery('.window').hide();
	});		
	
	//if mask is clicked
	jQuery('#mask').click(function () {
		jQuery('.window').hide();
		
		jQuery(this).fadeOut();		
		jQuery('#video *').remove();
		//jQuery(this).hide();
			
	});			
	
});
jQuery(window).resize(function(e) {
	//select all the a tag with name equal to modal
	
		//Cancel the link behavior
		e.preventDefault();
		
		var id = jQuery('a[name=modal]');
	
		//Get the screen height and width
		var maskHeight = jQuery(document).height()-5;
		var maskWidth = jQuery(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		
		
	
		//Get the window height and width
		var winH = document.documentElement.clientHeight;
		var winW = jQuery(window).width();
              
		//Set the popup window to center
		jQuery('#QuickTime').css('top',  '403px');
		jQuery('#QuickTime').css('left', winW/2-jQuery('#QuickTime').width()/2);
	
	
		jQuery('.MultiBoxContainer').css('top',  '403px');
		jQuery('.MultiBoxContainer').css('left', winW/2-jQuery('.MultiBoxContainer').width()/2);
});

