$(document).ready(function() {

	$(".topmenu").find(".greenBack").parent("LI").hover(
																			   function() {
																			   	$(this).css({ 'background-color': '#53BB4E' });
																			   	$(this).children("A").css({ 'background-color': '#53BB4E', 'color': '#FFFFFF' })
																			   },
																			   function() {
																			   	$(this).css({ 'background-color': '#FFFFFF' });
																			   	$(this).children("A").css({ 'background-color': '#FFFFFF', 'color': '#908371' })
																			   });
	$(".topmenu").find(".orangeBack").parent("LI").hover(
																			   function() {
																			   	$(this).css({ 'background-color': '#F9A95C' });
																			   	$(this).children("A").css({ 'background-color': '#F9A95C', 'color': '#FFFFFF' })
																			   },
																			   function() {
																			   	$(this).css({ 'background-color': '#FFFFFF' });
																			   	$(this).children("A").css({ 'background-color': '#FFFFFF', 'color': '#908371' })
																			   });
	$(".topmenu").find(".redBack").parent("LI").hover(
																			   function() {
																			   	$(this).css({ 'background-color': '#EA2839' });
																			   	$(this).children("A").css({ 'background-color': '#EA2839', 'color': '#FFFFFF' })
																			   },
																			   function() {
																			   	$(this).css({ 'background-color': '#FFFFFF' });
																			   	$(this).children("A").css({ 'background-color': '#FFFFFF', 'color': '#908371' })
																			   });
	$(".topmenu").find(".purpleBack").parent("LI").hover(
																			   function() {
																			   	$(this).css({ 'background-color': '#9A3795' });
																			   	$(this).children("A").css({ 'background-color': '#9A3795', 'color': '#FFFFFF' })
																			   },
																			   function() {
																			   	$(this).css({ 'background-color': '#FFFFFF' });
																			   	$(this).children("A").css({ 'background-color': '#FFFFFF', 'color': '#908371' })
																			   });
	$(".topmenu").find(".blueBack").parent("LI").hover(
																			   function() {
																			   	$(this).css({ 'background-color': '#00ADD0' });
																			   	$(this).children("A").css({ 'background-color': '#00ADD0', 'color': '#FFFFFF' })
																			   },
																			   function() {
																			   	$(this).css({ 'background-color': '#FFFFFF' });
																			   	$(this).children("A").css({ 'background-color': '#FFFFFF', 'color': '#908371' })
																			   });
	$(".topmenu").find(".darkBlueBack").parent("LI").hover(
																			   function() {
																			   	$(this).css({ 'background-color': '#002395' });
																			   	$(this).children("A").css({ 'background-color': '#002395', 'color': '#FFFFFF' })
																			   },
																			   function() {
																			   	$(this).css({ 'background-color': '#FFFFFF' });
																			   	$(this).children("A").css({ 'background-color': '#FFFFFF', 'color': '#908371' })
																			   });

	$(".sidemenu").find(".ekflexmenu_submenu_items_hidden").parent(".ekflexmenu_menu_level_1").css({ 'display': 'none' });

	$(".courseContent").hide();
	$("#whyStudyHeader").next(".courseContent").show();
	$("#summaryHeader").next(".courseContent").show();

	$("h2 > a").click(function(event) {

		$(this).parents("h2").next(".courseContent").slideToggle(1000);
		$(this).children("span").fadeOut(500, function() {

			if ($(this).hasClass("expanded")) {
				$(this).removeClass("expanded");
				$(this).addClass("contracted");
			}
			else {
				$(this).removeClass("contracted");
				$(this).addClass("expanded");
			}

			$(this).fadeIn(500);
		});

		return false;

	});

	//The entire image of a feature/news item can be clicked.	
	$(".feature img, .newsItem img").mouseover(function() {
		$(this).next("a").css({ 'text-decoration': 'underline' });
		window.status = $(this).next("a").attr("href");
	});

	$(".feature, .newsItem").mouseout(function() {
		$(this).find("a").css({ 'text-decoration': 'none' });
		window.status = "";
	});

	$(".feature a, .newsItem a").mouseover(function() {
		$(this).css({ 'text-decoration': 'underline' });
	});

	$(".feature img, .newsItem img").click(function() {

		var targetType = $(this).next("a").attr("target");
		var url = $(this).next("a").attr("href");

		if (targetType == "_blank") {
			window.open(url);
		}
		else {
			window.location.href = url;
		}

	});

	/*	//Chelgate holding page
	$('iframe').click(function(event) {
	var iFrameUrl = $(this).attr("src").val();
	alert(iFrameUrl);
	alert('hello');
	});

	jquery iframe click
	getSourceUrl?
	loadChelgateFrame
	scroll page to top
	*/
});

function loadChelgateFrame(chelgatePageSrc) {

   // Keep track of the iframe height.  
   var if_height,  
    
   // Pass the parent page URL into the Iframe in a meaningful way (this URL could be  
   // passed via query string or hard coded into the child page, it depends on your needs).     
   src = chelgatePageSrc + encodeURIComponent( document.location.href ),      
    
   // Append the Iframe into the DOM.    
   iframe = $( '<iframe src="' + src + '" width="474" height="100" scrolling="no" frameborder="0"></iframe>' )      
   .appendTo( '#iframe' ); 
  
   // Setup a callback to handle the dispatched MessageEvent event. In cases where  
   // window.postMessage is supported, the passed event will have .data, .origin and  
   // .source properties. Otherwise, this will only have the .data property.

   $.receiveMessage(function(e){  
   
     // Get the height from the passsed data.    
     var h = Number( e.data.replace( /.*if_height=(\d+)(?:&|$)/, '$1' ) );      
     
     if ( !isNaN( h ) && h > 0 && h !== if_height ) {       
       // Height has changed, update the iframe.       
       iframe.height( if_height = h );     
     }      
  
     // An optional origin URL (Ignored where window.postMessage is unsupported).
    }, 'http://www.pressrooms.net');

};

//Removes the Ektron Editor Markers image (silver bubble) and its associated menu from the DOM
function removeEditorsMarkers() {

	//function passed as an argument to the jQuery constructor is bound to the document ready event. 
	$(function() {		
		$("[class^='EktronEditorsMenu']").remove();	
	})

}

//Retrieves the Url for a CEM Rep
function getCemRepUrl() {
	return $("[id$='hdn_cemRepSystemUrl']").attr("value");
}

//load the JW player and embed into an object
function ShowVideo(parameters) 
{

	$(function() {

	var BodyColour;
	
	//Default settings
	if (parameters.videoPath == undefined) parameters.videoPath = "";
	if (parameters.imagePath == undefined) parameters.imagePath = "";
	if (parameters.title == undefined) parameters.title = "";
	if (parameters.playList == undefined) parameters.playList = "bottom";
	if (parameters.playListSize == undefined) parameters.playListSize = "0";
	if (parameters.id == undefined) parameters.id = "playerID";
	if (parameters.playerWidth == undefined) parameters.playerWidth = "474";
	if (parameters.playerHeight == undefined) parameters.playerHeight = "286";
	if (parameters.autoStart == undefined) parameters.autoStart = "false";
	if (parameters.BodyColour == undefined) {
		switch (getBodyColour())
		{
			case "orangeBack":
				BodyColour = "F9A95C";
				break;
			case "greenBack":
				BodyColour = "53BB4E";
				break;
			case "blueBack":
				BodyColour = "00ADD0";
				break;
			case "purpleBack":
				BodyColour = "9A3795";
				break;
			case "redBack":
				BodyColour = "EA2839";
				break;
			case "darkBlueBack":
				BodyColour = "002395";
				break;																
			default:
				BodyColour = "53BB4E";
				break;																
		}
	}
	else {
		BodyColour = parameters.BodyColour;
	}
	
	var flashvars =
      {
      	'file':							'http://' + document.domain + parameters.videoPath,
      	'image':							parameters.imagePath,
      	'title':						parameters.title,
      	'playlist':							parameters.playList,
      	'playlistsize':						parameters.playListSize,
      	//'plugins':        'http://static.cem.ac.uk/lib/jwplayer/plugins/captions.swf,http://static.cem.ac.uk/lib/jwplayer/plugins/hd.swf', - Multiple plugins
      	//'plugins':		   	'plugins/captions.swf',
      	//'captions.file':			'captions.xml',
      	//'captions.state':			'false',
      	//'captions.back':			'true',
      	//'captions.fontsize':	'14',
      	'backcolor':						'FFFFFF',  // face of buttons
      	'frontcolor':				'000000',  // button symbols & playlist text
      	'lightcolor':				BodyColour,  // highlighted playlist item
      	'screencolor':			'000000',  // screen background color
      	'id':								parameters.id,
      	'autostart':						parameters.autoStart
      };

	var params =
      {
      	'allowfullscreen': 'true',
      	'allowscriptaccess': 'always',
      	'bgcolor': '#FFFFFF'
      };

	var attributes =
      {
      	'id': 'playerID',
      	'name': 'playerID'
      };

      swfobject.embedSWF('http://static.cem.ac.uk/lib/jwplayer/player.swf', 'player', parameters.playerWidth, parameters.playerHeight, '9.0.124', false, flashvars, params, attributes);

	})
}

/*****************************************************************
Photo Gallery
*****************************************************************/

$(document).ready(function() {

	if ($('#gallery').length) {
		var slide = 0;
		$galMaster = $('#gallery');	
		$galList = $('#galList');
		$galMaster.children().first().attr('src', imgTrim($('#galList img').first()));

	}

	$('#gallery #galList a').click(function() {
		$galMaster.children().first().attr('src', imgTrim($(this).children('img')));
		return false;
	})

	$('#gallery #galList img').hover(function() {
		$(this).css('opacity', 1);
		$(this).parents('li').css('background-color', '#FFF')

	},
							function() {
								$(this).css('opacity', 0.8)
								$(this).parents('li').css('background-color', '#00ADD0')
							}
							)
	$('#gallery #galList a').focus(function() {
		$(this).css('opacity', 1);
		$(this).parent().css('background-color', '#FFF');

	});

	$('#gallery #galList a').blur(function() {
		$(this).css('opacity', 0.8);
		$(this).parent().css('background-color', '#00ADD0');
	}
							)

	$('#gallery #right').click(function() {

		if (slide >= 4) {
			return false;
		}
		else {
			slide++
			$galList.animate({ marginTop: (-238 * slide) }, 500)
			$('#left').css('opacity', 1);
			if (slide >= 4) $(this).css('opacity', 0.5)
			return false;
		}
	})


	$('#gallery #left').click(function() {

		if (slide <= 0) {
			return false;
		}
		else {
			slide--
			$galList.animate({ marginTop: (-238 * slide) }, 500)
			$('#right').css('opacity', 1);
			if (slide <= 0) $(this).css('opacity', 0.5)
			return false;
		}
	})


	function imgTrim(old) {
		oldSrc = old.attr('src')
		newSrc = oldSrc.replace("THUMB_", "")
		//newSrc = "/uploadedimages/Gallery/ChinaReception/" + oldSrc.slice(start)
		return newSrc
	}


});




