// Simple slideshow


function simpleSlideshow(contID){
	
	
	var __thisContainer = '#' + contID;
	
	
	$(__thisContainer).find('a').each(function () {
		$(this).bind('click', function(){
			
			$(__thisContainer).find('a.active').removeClass('active');
			var __newImg = $(this).attr('href');
			var __newCaption = $(this).attr('rel');
			var __newAlt = $(this).find("img").attr('alt');
			$(__thisContainer).find('.mainImage').attr('src', __newImg);
			$(__thisContainer).find('.mainImage').attr('alt', __newAlt);
			$(__thisContainer).find('.caption').text( __newCaption);
			$(this).addClass('active');
			return false;
		});
		
	});

}


function resizeLB(){

	
	
}


function buttons(){

	//Add a class to the body for the different print view
	$("body").addClass("modal");

	//Update CSS
	var cont = document.getElementById("tableContainer");
	cont.style.width = "250px";
	cont.innerHTML="";	


	var __print = document.createElement("a");
	__print.href="#";
	__print.innerHTML = "Print this page";
	__print.style.display = "block";
	__print.style.width = "auto";
	__print.style.cssFloat = "right";
	__print.style.styleFloat = "right";
	__print.style.height = "15px";
	__print.style.background = "url(http://www.bp.com/images/print_icon.gif) left top no-repeat";
	__print.style.padding = "0 0 0 18px";
	__print.onclick = function(){
		
		self.print();
		return false;
	} 
	
	
	var __close = document.createElement("a");
	__close.href="#";
	__close.innerHTML = "Close window";
	__close.style.display = "block";
	__close.style.width = "auto";
	__close.style.cssFloat = "right";
	__close.style.styleFloat = "right";
	__close.style.height = "15px";
	__close.style.background = "url(http://www.bp.com/images/close_icon.gif) left top no-repeat";
	__close.style.padding = "0 0 0 18px";
	__close.style.margin = "0 0 0 30px";
	__close.onclick = function(){
		window.closeCB();
		return false;
	}
	
	cont.appendChild(__close);
	cont.appendChild(__print);
	__close.focus();
	
}


		
		
function closeCB(){
	$.colorbox.close();
}

$(function() {
// set up so that there can be more than one slideshow on the page if necessary
// test for the existance of the slideshow, then loop through each instance and call the function
// each slideshow will need a unique ID
	if($('div.slideshow').length){
		$('div.slideshow').each(function (){
			var contID = $(this).attr('id');
			simpleSlideshow(contID);
		});
	}
	
	
	var colBoxWidth;
	
	var _detect = navigator.userAgent.toLowerCase();
	var _IE = (_detect.indexOf("msie") >=0 && (_detect.indexOf("7") >= 0 || _detect.indexOf("6") >= 0)) ? 1 : 0; 
	_IE ? colBoxWidth = "630px" : colBoxWidth = "620px"
	
	$("a.lightbox").colorbox({ 
		onClosed:function(){$("body").removeClass("modal");}	
	}, function(){
		$('#cboxLoadedContent').find('iframe').attr('scrolling','false');
		$.colorbox.resize();
		buttons();
	});
	
	
/*	$("a.lightbox-fixed").colorbox({
		width:"620px", 
		height:"500px"
	}, function(){
		buttons();
	})
*/
 $("a.lightbox-fixed").colorbox({

                        width:"782px", 

                        height:"650px", 

                      scrolling:true,  iframe:true,
'opacity':'0.5',
'-moz-opacity':'0.5',
'filter':'alpha(opacity=50)'

            })

	

	

})

