/**********js code to detect wmp player************************/
//display download link if wmp is not installed

if(!detectWMP())
{//alert("wmp not detect");
	var downloadUrl;
	var downloadText = "click here to download Windows Media Player";
	var agentStr= window.navigator.userAgent.toLowerCase();
	if (agentStr.indexOf("msie") >= 0)
		downloadUrl = "http://www.microsoft.com/windows/windowsmedia/download/AllDownloads.aspx";
	else if (agentStr.indexOf("opera") >= 0)
		downloadUrl = "http://www.softpedia.com/get/Tweak/Browser-Tweak/Media-Player-Plugin-for-Opera.shtml";
	else if (agentStr.indexOf("firefox") >= 0)
		downloadUrl = "http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx";
	else if (agentStr.indexOf("netscape") >= 0)
		downloadUrl =  "http://www.microsoft.com/windows/windowsmedia/player/version64/plugin.aspx";	
	else if (isSafari())
		downloadUrl = "http://www.microsoft.com/mac/otherproducts/otherproducts.aspx?pid=windowsmedia";	
	else
		downloadUrl = "http://www.microsoft.com/downloads/Search.aspx";	
	var player = document.getElementById("player1_window");
	if (player)
		player.innerHTML = "<div id='divPlayerError' style='font-size:1.2em;padding-top:5px;padding-left:5px;width:350px;height:300px;line-height:1.2em'>If you can't see the video playing, then please <a href='"+downloadUrl +"' target=_blank>"+downloadText+"</a><br/><br/>Once you have downloaded the plug-in, you will need to refresh this browser window, then the video will start playing.</div>";
		//player.innerHTML = player.innerHTML + "<div id='divPlayerError'><a style='line-height:20px;font-size:12px;' href='"+downloadUrl +"' target=_blank>"+downloadText+"</a></div>";
}
else
{//alert("wmp  detect");
	var divError = document.getElementById("divPlayerError");
	if (divError)
		divError.innerHTML = "";
}

// adjust video thumbnails position
var vdoThbpicContainer1 = document.getElementById("city_1_link").parentElement;
var vdoThbpicContainer2 = document.getElementById("city_2_link").parentElement;
var vdoThbpic3 = document.getElementById("city_3_link");
if (!vdoThbpic3)
{
	vdoThbpicContainer1.style.margin = "5px 0px 0px 45px";
	vdoThbpicContainer2.style.margin = "5px 0px 0px 50px";
}

//detect whether the wmp player/plugin is installed
function detectWMP()
  {		
		var isInstalled = false;
		//detect IE
		if(window.ActiveXObject)
		{		
			isInstalled = detectWmpPlayer();
		}
		//detect Mozilla
		else
		{
			if (!detectWmpPlugin())
				isInstalled = false;
			else
			{
				if (!IsPluginEnable())
					isInstalled = false;
				else
					isInstalled = true;
			}
		}
		return isInstalled;
  }

//detect whether the wmp player is installed
function detectWmpPlayer()
{		
	try
	{
		var player = new ActiveXObject("WMPlayer.OCX.7");//alert(player.versionInfo);
		var version = player.versionInfo;
		version = version.substring(0,version.indexOf("."));
		if (version < 9)
			return false;
	}
	catch(e)
	{
		return false;
	}
	return true;	
}

//detect whether the plugin for wmp is installed
function detectWmpPlugin() 
{
	var wmpPluginName = "windows media player";  //windows
	var wmpPluginName_safari = "windows media plugin"; //mac, but this plugin can't play our videos: flip4mac windows media plugin
    var pluginFound = false;   
    if (navigator.plugins && navigator.plugins.length > 0) 
    {
		var pluginsArrayLength = navigator.plugins.length;
		for (var i=0; i < pluginsArrayLength; i++ ) 
		{//alert(navigator.plugins[i].name.toLowerCase());
			if(navigator.plugins[i].name.toLowerCase().indexOf(wmpPluginName) >= 0 || navigator.plugins[i].description.toLowerCase().indexOf(wmpPluginName)>=0)
			{
				return true;
			}		
			else if (navigator.plugins[i].name.toLowerCase().indexOf("flip4mac") < 0 && (navigator.plugins[i].name.toLowerCase().indexOf(wmpPluginName_safari) >= 0 || navigator.plugins[i].description.toLowerCase().indexOf(wmpPluginName_safari)>=0))
				return true;
			
		}
    }
   return false;
} 

//detect  whether the plugin is enabled
function IsPluginEnable()
{
	var fHasWMP52 = navigator.mimeTypes && navigator.mimeTypes["application/x-mplayer2"] &&  navigator.mimeTypes["application/x-mplayer2"].enabledPlugin;
	var fHasWMP64 = navigator.mimeTypes && navigator.mimeTypes["video/x-ms-wm"] &&  navigator.mimeTypes["video/x-ms-wm"].enabledPlugin && navigator.mimeTypes["video/x-ms-wmv"] && navigator.mimeTypes["video/x-ms-wmv"].enabledPlugin;

	if( fHasWMP64 ) 
	{
		return true;//alert("version 6.4 or higher.");
	}
	else if( fHasWMP52 )
	{
		return true;//alert("version 5.2 or higher.");
	}
	else
	{
		return false;
	}
}

//detect Safari
function isSafari()
{
	//return (document.childNodes)&&(!document.all)&&(!navigator.taintEnabled)&&(!navigator.accentColorName);
	return window.navigator.userAgent.toLowerCase().indexOf("safari") >= 0;	
}

var cornwall = new Object();
cornwall.clipUrls = new Array();
cornwall.clipUrls[0] = "mms://msnukwm.fplive.net/msnuk/theaa/wales_vid_01_duo.wmv";
cornwall.clipUrls[1] = "mms://msnukwm.fplive.net/msnuk/theaa/wales_vid_02_duo.wmv";
cornwall.clipUrls[2] = "mms://msnukwm.fplive.net/msnuk/theaa/aa_scot_03.wmv";

cornwall.video = document.getElementById("vedio_main");

function changeBackground(index)
{
    var city1 = document.getElementById("city_1_link").parentElement;
    var city2 = document.getElementById("city_2_link").parentElement;
    //var city3 = document.getElementById("city_3_link").parentElement;
    
    city1.style.color = '#FFFFFF';
    city1.style.backgroundColor = "#000000";
    city2.style.color = '#FFFFFF';
    city2.style.backgroundColor = "#000000";
    //city3.style.color = '#FFFFFF';
    //city3.style.backgroundColor = "#000000";
    
    eval("city" + index + ".style.color = '#000000';");
    eval("city" + index + ".style.backgroundColor = '#F9C843';");
}

window.onload = function()
{
   document.getElementById("city_1_link").attachEvent("onclick",playClip1);
   document.getElementById("city_2_link").attachEvent("onclick",playClip2);
   //document.getElementById("city_3_link").attachEvent("onclick",playClip3);
}

function playVideo(source)
{
    if(cornwall.video)
    {
        var BrowserType=navigator.userAgent.toLowerCase(); 
        if(BrowserType.indexOf("msie")>=0 && BrowserType.indexOf("opera")<0)
        {
            cornwall.video.URL = source;
        }
        else
        {
            cornwall.video.innerHTML = "<embed autostart=\"1\" height=\"335\" fullscreen=\"0\" uimode=\"full\"  loop=\"true\" src=\"" + source + "\" width=\"360\"></embed>";        
        } 
    }   
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    }
    else {
        return document[movieName];
    }
}

function goContent(index) 
{
		thisMovie("Flash_content").goContent(index);
}
 
function playClip1()
{
    changeBackground(1);
    goContent(0);
    playVideo(cornwall.clipUrls[0]);
} 
function playClip2()
{
    changeBackground(2);
    goContent(1);
    playVideo(cornwall.clipUrls[1]);
} 
function playClip3()
{
    changeBackground(3);
    goContent(2);
    playVideo(cornwall.clipUrls[2]);
}