function createPlayer(theFile) {

	var flashMovie = new SWFObject("inc/flash/player.swf", "player1", "900", "450", "8.0.15", "#000000", true);
	flashMovie.addParam("allowScriptAccess", "always");
	flashMovie.addParam("allowFullScreen", "true");

	flashMovie.addVariable("file", theFile);
	flashMovie.addVariable("autostart", "false");
	flashMovie.addVariable("bufferlength", "10");
	flashMovie.addVariable("buffer", "10");
	flashMovie.addVariable("playlistsize", "240");
	flashMovie.addVariable("displaywidth", "320");
	flashMovie.addVariable("playlist", "right");
	flashMovie.addVariable("backcolor", "#575757");
	flashMovie.addVariable("wmode", "opaque");
	flashMovie.addVariable("frontcolor", "#FFFFFF");
	flashMovie.addVariable("stretching","fill");
	flashMovie.addVariable("displayclick","none");
	flashMovie.write("teatroPavanaMedia");

}


function createPlayerAdmin(theVideo, width, height) {

	var flashMovie = new SWFObject("../inc/flash/player.swf", "player", width, height, "8.0.15", "#000000", true);
	flashMovie.addParam("allowScriptAccess", "always");
	flashMovie.addParam("allowFullScreen", "true");

	flashMovie.addVariable("file", theVideo);
	flashMovie.addVariable("autostart", "true");
	flashMovie.addVariable("bufferlength", "10");
	flashMovie.addVariable("buffer", "10");
	flashMovie.addVariable("backcolor", "#FFFFFF");
	flashMovie.addVariable("wmode", "transparent");
	flashMovie.addVariable("frontcolor", "#000000");
	flashMovie.addVariable("stretching","fill");
	flashMovie.addVariable("displayclick","none");
	flashMovie.write("videoDisplay");

}


function displayFlashVideoPlayer(action) {

	switch(action) {

		case 'hide':
			$('#teatroPavanaMedia').css('display', 'none');
			break;

		case 'visible':
			$('#teatroPavanaMedia').css('display', 'block');
			break;

	}
}


function createFlashObject(parentId, flashMovie, bgColor, width, height, params) {

	var MM_contentVersion = 6;
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
		for (var i = 0; i < words.length; ++i) {
			if (isNaN(parseInt(words[i])))
				continue;
			var MM_PluginVersion = words[i]; 
		}
		var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;

	} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {

		try {
			// Try 7 first, since we know we can use GetVariable with it
			var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.7');
			flashVersion = getFlashVersion(ax.GetVariable('$version'));
		} catch (e) {
		      // Try 6 next, some versions are known to crash with GetVariable calls
		    try {
		      var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
		      MM_FlashCanPlay = '6.0.21';  // First public version of Flash 6
		    } catch (e) {
			  try {
		        // Try the default activeX
				var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
				MM_FlashCanPlay = getFlashVersion(ax.GetVariable('$version'));
		      } catch (e) {
				 // No flash
		      }
		    }
		}
	}
	if ( MM_FlashCanPlay ) {
		var flashMovie = new SWFObject(flashMovie, parentId+"flash", width, height, "8.0.15", "#000000", true);
		flashMovie.addParam("allowScriptAccess", "always");
		flashMovie.addParam("allowFullScreen", "false");
		if(params!==false) 
			flashMovie.addParam("FlashVars", params);
		flashMovie.write(parentId);
	} else if(width>150 && height>60)
		$(('#'+parentId)).html('<p align="center"><b>Some parts of this site require the adobe flash player,'
							   + '<br> please click the image below to install the flash player.</b></p>'
							   + '<p align="center"><a href="http://get.adobe.com/flashplayer/" target="_blank">'
							   + '<img src="images/get_flash_player.gif" alt="Get Adobe Flash Player" border="0" /></a></p>');

}


function setCookie(name, value) {

	document.cookie = name + '=' + escape(value);

}


/**
@description			get the music preference of the visitors and returns it 
						when not set it sets the music preference in the cookie to 'on'
@return					on/off
*/
function musicPreference() {

	var reg = /(on|off)/;
	var musicPreference = getCookie('musicPreference');
	if(musicPreference===false) {
		setCookie('musicPreference', 'off');
		musicPreference = 'off';
	}
	if(musicPreference.search(reg)==-1)
		musicPreference = 'on';
	return musicPreference;		

}


/**
@description				get the value from the cookie with the name c_name
@param string c_name		name of the value in the cookie
@return boolean, string		false when the name was not found, the value when it was
*/
function getCookie(c_name) {

	if (document.cookie.length>0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)  {
			c_start = c_start + c_name.length+1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end==-1) 
				c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return false;
}


/**
@description				refreshes the menu/heading of the site to the right language
							gets a new page with an ajax request and displays it in div with id teatroPavanaContent
@param string type			type of menu needed
@param integer languageId	id of the language
*/
function getMenuAndPage(type, languageId) {

	
	var prefix = (($.browser.msie===true) ? 'ie' : 'mz') + '-ajax-';
	
	//Set the cookie to the right language
	setCookie('languageId', languageId); 
	
	//Includes the languageId in the request below to solve a safari problem
	switch(type) {
		case 'menu':
			var layer = '#menu';
			var menu = 'menu.inc.html-language-'+languageId;
			break;
		case 'heading':
			var layer = '#teatroPavanaHeading';
			var menu = 'heading.inc.html-language-'+languageId;
			break;
	}
	
	//Empty all the layers
	$(layer).html('');
	$("#teatroPavanaContent").html('');

	//First change the language of the main content
	getPage('language-'+languageId+'.html');
	
	//Request the menu or heading
	$.ajax({
	  url: prefix + menu,
	  cache: false,
	  dataType: "html",
	  success: function(html){
			
			//Adding the menu/heading to the top
			$(layer).html(html);
			switch(type) {

				case 'heading':		
					
					//Initiliaze the flash file in the heading
					createFlashObject('teatroPavanaHeadingPhotos'
									  , 'inc/flash/teatroPavanaHeader.swf'
									  , '#19171c'
									  , 960
									  , 99
									  , false);
					break;
			}	

			//Make sure the li:hover work when ajax requested for explorer <7.0
			if(window.parseStylesheets)
				window.parseStylesheets();

	  }
	});

}


/**
@description					gets a new page with an ajax request and displays it in div with id teatroPavanaContent
@param string request			the requested page
*/
function getPage(request) {

	request = (($.browser.msie===true) ? 'ie' : 'mz') + '-ajax-' + request;

	$.ajax({
	  url: request,
	  cache: false,
	  dataType: "html",
	  success: function(html){

		$("#teatroPavanaContent").html('');
		$("#teatroPavanaContent").append(html);

		//Execute all the javascription inside the executeAjax() in the responseText
		if(jsMusicControl=='on' && musicPreference()=='on')	
			backgroundMusic('on');

		executeAjax();
			
	  }
	});
}


//hash to check if javascript messed with the sound on the video page
var jsMusicControl = false;

/**
@description			controls the flash movie sound, puts it on or off
@param string action	on/off
*/
function backgroundMusic(action) {

	var flashMovie = getFlashMovieObject("backgroundSoundflash");
	switch(action) {

		case 'on':
			jsMusicControl = false;
			flashMovie.musicControl('on');
			break;

		case 'off':
			jsMusicControl = 'on';			
			flashMovie.musicControl('off');
			break;


	}
}


/**
@description				gets tge flash movie object for javascript to control
							flash movies
@param string movieName		name of the flash movie				
*/
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}


/*		Admin area		*/

function moveRow(headingId, reference, direction) {

	switch(direction) {

		case 'up':

		   var $thisRow = $(reference).parents('tr:first');

		   var $prevRow = $thisRow.prev();
		   $thisRow.insertBefore( $thisRow.prev() );

		   $('#'+headingId).insertBefore( $('#'+headingId).prev() );
		   break;

		case 'down':
		   var $thisRow = $(reference).parents('tr:first');
		   $thisRow.insertAfter( $thisRow.next() );
			break;

	}
} 


/**
@description						hides all html elements in allElements and show only the currentElement
@param string currentElement		the current element		
@param array allElements			an array with all the elements inside including the current
*/
function swapElements(currentElement, allElements, prefix) {

	if(prefix==undefined)		prefix = '';
	$(prefix+currentElement).css('display', 'block');	

	for(var i in allElements) {
		if(allElements[i]!=currentElement)
			$(prefix+allElements[i]).css('display', 'none');
	}
}




function addDatePickerToElements(elements, options) {

	for(var i in elements) {

		options['onChange'] = function(formated, dates){
								$(elements[i]).val(formated);
								$(elements[i]).DatePickerHide();
							  };
							  alert(options['onChange']);
		$(elements[i]).DatePicker(options);

	}
}


function searchArray(array, value) {
	
	for(var i =0; i<array.length; i++) {
		if(array[i]==value)		return i;
	}
	return false;
}


function searchKeyArray(array, key) {
	
	for(var arrayKey in array) {
		if(key==arrayKey)		return true;
	}
	return false;

}