$(document).ready(function(){
	/*
	*
	*
	*	USER-DEFINED COLORBOX CODE FROM HERE DOWNWARDS
	*
	*
	*/	
	
	//For the Great War video popups - set iframe to true, and height/width of video iframe
	$(".great-war-video").colorbox({iframe:true, width:"400px", height:"400px", current: "Transcript<span class=\"white-arrow-small\"></span>", video: true});
$(".great-war-transcript").colorbox({iframe:true, width:"700px", height:"700px", current: "Video<span class=\"white-arrow-small\"></span>", video: true});
	
	//Set title text of ColorBox to text contained within the a tag (link) - this colorbox has no other variables set
	$(".popup").each(function(){ $(this).colorbox({title: $(this).text()});}); 
	
	//Set title text of ColorBox to 'alt' tag of picture contained within the a tag - this colorbox has no other variables set
	$(".popup-img").each(function(){ $(this).colorbox({title: $(this).find("img").attr('alt')});}); 
	
	
	//Set iframe to true, and height/width of video iframe
	$(".records-video").colorbox({iframe:true, width:606, height:542, current: "Transcript<span class=\"white-arrow-small\"></span>", video: true});	/*Increased height by 8px to remove scrollbars in lightbox DW 20/01/12*/

	//Set iframe to true, and height/width of transcript iframe
	$(".records-transcript").colorbox({iframe:true, width:606, height:534, current: "Video<span class=\"white-arrow-small\"></span>", video: true});
	//Set iframe to true, and height/width of transcript iframe
	$(".record-copying").colorbox({ width:"50%", title:true, inline:true, href:"#inline"});
	
	/*
	*
	*	DEFAULT EXAMPLES OF COLORBOX CODE FROM HERE DOWNWARDS
	*
	*	'width: xxx, height: xxx' - set width and height of lightbox manually
	*	'maxWidth: xxx, maxHeight: xxx - set maximum width and height of lightbox
	*	'scalePhotos: true' - if maxWidth, maxHeight, innerWidth, innerHeight, width, or height have been defined, lightbox will scale photos to fit within the those values.
	*	'title: true' - lightbox header displays title of image, link or iframe - this is set either in the title tag or alt tag of the link (see popup and popup-img at top of file)
	*	'transition: fade', 'elastic' or 'none' - sets transition between items. Set by default to 'elastic'
	*	'slideshow: true' - start slideshow of images/items when lightbox opens
	*	'inline:true' - a jQuery selector can be used to display content from the current page. Example: $(".< class >").colorbox({inline:true, href:"#myForm"}); 
	*	'iframe: true' - link opens in an iframe (seperate page) inside lightbox	
	*	'current: "< text or html >"' - sets 'current' text in lightbox header
	*	'video: true' - remove lightbox previous and next buttons and replace with 'current' text/link above
	*
	*/
	//Assign the ColorBox event to elements
	//$(".popup-img").colorbox(); - default popup image colorbox event
	$(".popup-page").colorbox({iframe:true, width:790, height:"90%", title:true});
	$(".understand-iframe").colorbox({width:"756px", height:"565px", iframe:true, title:true});
	$(".wide").colorbox({width:850});
	
	//other default examples - for image galleries
	$("a[rel='example1']").colorbox({title:true});
	$("a[rel='example2']").colorbox({title:true,transition:"fade"});
	$("a[rel='example3']").colorbox({title:true, width:"75%", height:"75%"});
	$("a[rel='example4']").colorbox({title:true, slideshow:true});
	//other default examples
	$(".colorbox").colorbox();
	$(".youtube").colorbox({iframe:true, width:650, height:550});
	$(".inline").colorbox({width:"50%", inline:true, href:"#inline_example1"});
	$(".inline-player").colorbox({inline:true, title:true, href:"#player"});
	
	//Example of preserving a JavaScript event for inline calls.
	$("#click").click(function(){ 
		$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
		return false;
	});	
	
	/*
	*
	*
	*	COLORBOX CODE NEEDED FOR WEBTRENDS, FIX GLITCHES IN IE8, REMOVE SCROLL BARS, ETC, BELOW
	*
	*
	*/	
	// removes scroll bars from all non-IE browsers when the colorbox is open
	$().bind('cbox_open', function(){$('html').css({overflow:'hidden'});}).bind('cbox_closed', function(){$('html').css({overflow:'auto'});});
	
	//check if browser is IE8 for iframe/Flash glitch
	var ver = getInternetExplorerVersion();
	// function to send to webtrends on close - check for iframe, send back name of iframe in the webtrends function for tracking - and clean up IE8 Flash glitch
	$().bind('cbox_cleanup', function(){
		// check if page has an iframe - else skip this function and close as normal
		if (frames.length > 0) {var frameObj;
		//for IE vs other browser differences in calling iframe
		if (document.frames){frameObj = document.frames[0].document;}else{frameObj = document.getElementById("cboxIframe").contentDocument;}
		// send multitrack function
		//dcsMultiTrack('DCS.dcsuri',document.getElementById('cboxIframe').src,'WT.ti',frameObj.title+'ClickAway');
		dcsMultiTrack('DCS.dcsuri',document.getElementById('cboxIframe').src,'WT.ti',frameObj.title+'%20ClickAway','WT.si_n','MoviePlayer','WT.si_p','ClickAway');
		//alert('DCS.dcsuri'+'-'+document.getElementById('cboxIframe').src+' '+'WT.ti'+'-'+frameObj.title+'%20ClickAway'+' '+'WT.si_n'+'-'+'MoviePlayer'+' '+'WT.si_p'+'-'+'ClickAway');
		// if IE8, access the iframe and close it to remove the Flash player glitch
		if (ver >= 8.0) {
			var iframe = document.getElementById('cboxIframe');var doc = iframe.contentDocument;if(doc == undefined || doc == null)doc = iframe.contentWindow.document;doc.open();doc.close();
			}
		}
	});   	
	
	//Disable caching
	$.ajaxSetup ({cache: false}); 
});

//function for checking for IE8
function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
