// -------------
//--- JQUERY ---
// -------------
jQuery(document).ready(function () { //HTML DOM document is ready
	
	// Metrics hash value - used to obtain metrics from vanity URLs
	if ((window.location.hash.substr(0,5)==="#ref_") && (typeof(s) != 'undefined')) {
	thisHash=window.location.hash.substr(5,window.location.hash.length-5);
	s.tl(true,'o','Referrer: ' + thisHash);
	}

	
	//get pageid
		var addressSearch = window.location.search,
		re = new RegExp('.*?'+'(\\d+)',"i"),
		pageID = re.exec(addressSearch);
		if ((pageID==null) || (pageID=='undefined')) {pageID="?pageid=1,1"};
		pageID = pageID[1];

	//major projects click
	jQuery("#navigation a.majorprojects").live("click", function() {
			jQuery("#projectdropdown2").removeClass("hidden");													 	
		
		//ie6 fix to make links work when inside pngfix div
		jQuery("#navigation #projectdropdown2").find("div.dropdown_body a:visible").removeClass("ie6pos");
		
		jQuery("#navigation #projectdropdown2 div.dropdown_body").slideToggle('slow', function() {
   			//ie6 fix
			jQuery("#navigation #projectdropdown2").find("div.dropdown_body a:visible").addClass("ie6pos");
  		});

		jQuery(this).toggleClass("majorprojects_lit");
		
		if( typeof(s) !== "undefined") {
			s.tl(true,'o','Major projects :pageid'+pageID);
		}
		
		return false;											
	});


	jQuery("#subnavigation div.tools ul li.printpage").css("display","block").find("a").live("click", function(){
		window.print();
		return false
	});
	jQuery("#subnavigation div.tools ul li.mytullow form input.add").live("mouseover", function(){
		jQuery(this).addClass("addroll");
	}).live("mouseout", function(){
		jQuery(this).removeClass("addroll");
	});
	$("#subnavigation div.tools ul li.mytullow form").submit(function() {
		var thishref = "managed_content/mytullow/mytullow_bookmark.asp",
		    serializedform = jQuery(this).serializeArray();
		jQuery.ajax({
			data: serializedform,
			type: "POST",
			url: thishref,
			timeout: 2000,
			success: function(data){
				jQuery("#subnavigation div.tools ul li.mytullow").replaceWith(data);
			}
		});
		return false;
	});
	$("a[rel*=facebox]").facebox();

	$("form.playlistform").submit(function() {
		var thishref = "managed_content/mytullow/mytullow_videoplaylist.asp",
		    serializedform = jQuery(this).serializeArray(),
		    thiscontainer = jQuery(this).parent();
		jQuery.ajax({
			data: serializedform,
			type: "POST",
			url: thishref,
			timeout: 2000,
			success: function(data){
				jQuery(thiscontainer).html(data);
			}
		});
		return false
	});









	jQuery("#navigation #projectdropdown2:not(.show) div.dropdown_body").slideUp("fast", function() {
		jQuery("#navigation #projectdropdown2").removeClass("hide");
	});	
	
	//Our websites click
	jQuery("#sitefeatures a.majorprojects").live("click", function() {	
		var currentlink = jQuery(this);														   
		jQuery("#projectdropdown").removeClass("hidden");
		
		//ie6 fix to make links work when inside pngfix div
		jQuery("#sitefeatures #projectdropdown").find("div.dropdown_body a:visible").removeClass("ie6pos");
		jQuery("#navigation li.majorprojects").addClass("relative");
		jQuery("#navigation #projectdropdown2:not(.show) div.dropdown_body").hide();
		jQuery("#sitefeatures #projectdropdown div.dropdown_body").slideToggle('slow', function() {
   			//ie6 fix
			jQuery("#sitefeatures #projectdropdown").find("div.dropdown_body a:visible").addClass("ie6pos");
  		});

		jQuery(currentlink).toggleClass("majorprojects_lit");
		
		if (currentlink.hasClass("majorprojects_lit")) {
			jQuery("#navigation li.majorprojects").removeClass("relative");
		}else{
			jQuery("#navigation li.majorprojects").addClass("relative");
		}
		
		if( typeof(s) !== "undefined") {
			s.tl(true,'o','Our websites:pageid'+pageID);
		}
		
		return false;											
	});
	
	jQuery("#sitefeatures #projectdropdown:not(.show) div.dropdown_body").slideUp("fast", function() {
		jQuery("#sitefeatures #projectdropdown").removeClass("hide");
	});	
				
	jQuery("input[type=text]").bind('focus',function() {  // only select if the text has not changed
	  if(this.value == this.defaultValue) {
		  this.select();
	  }
	});
	
	//image rollover
	jQuery("a.roll").live('mouseover focus', function(event) {
		jQuery(this).find('img').attr("src", jQuery(this).find('img').attr("src").split('_f1').join('_f2'))
	}).live('mouseout blur', function(event) {/*mouseout*/
		jQuery(this).find('img').attr("src", jQuery(this).find('img').attr("src").split('_f2').join('_f1'))
	});

	//image rollover
	jQuery("a.rollbg, a.rollpngbg").live('mouseover focus', function(event) {
		jQuery(this).css('background-image', jQuery(this).css('background-image').split('_f1').join('_f2'));
	}).live('mouseout blur', function(event) {/*mouseout*/
		jQuery(this).css('background-image', jQuery(this).css('background-image').split('_f2').join('_f1'));
	});

	//table row rollover
	jQuery.each(["table:not(.nohover) tbody tr:not(.nohover)"], function(index, value) { 
  		jQuery(value).live('mouseover mouseout', function() {
			jQuery(this).toggleClass("hover");
		});
	});

	//open links in a new window - rel=external
	jQuery("a[rel=external]").attr("target","_blank").each(function(n) {
		jQuery(this).attr("title") !='' ? this.title=jQuery(this).attr("title")+'. Opens in a new browser window.' : this.title='Opens in a new browser window.';
	});
	
	//webcast popups
	jQuery("a[rel=webcast_popup]").live("hover focus", function() {
		if (typeof(jQuery(this).data("external")) === "undefined") {
			jQuery(this)
				.attr("target","_blank")
				.data("external",1)
				.attr("title") !=='' ? this.title=jQuery(this).attr("title")+'. Opens in a new browser window.' : this.title='Opens in a new browser window.';	
		}
	}).live("click", function() {
		window.open(jQuery(this).attr('href'), 'popup_window', 'width=750,height=580,location=1,resizable=1,status=0,scrollbars=1').focus();
        return false;
    });

	jQuery("a[rel=presentation_popup]").live("hover focus", function() {
		if (typeof(jQuery(this).data("external")) === "undefined") {
			jQuery(this)
				.attr("target","_blank")
				.data("external",1)
				.attr("title") !=='' ? this.title=jQuery(this).attr("title")+'. Opens in a new browser window.' : this.title='Opens in a new browser window.';	
		}
	}).live("click", function() {
		window.open(jQuery(this).attr('href'), 'popup_window', 'width=815,height=600,location=1,resizable=1,status=0,scrollbars=1').focus();
        return false;
    });

	//form button rollovers
	jQuery("form button.formbutton").live("mouseover mouseout focus blur", function() {
		jQuery(this).toggleClass("formbutton_f2");
	});
	
	//form button rollovers
	jQuery("form button.submitbtn").live("mouseover mouseout focus blur", function() {
		jQuery(this).toggleClass("submitbtn_f2");
	});
	
	//form button rollovers
	jQuery("form button.sharepricebtn").live("mouseover mouseout focus blur", function() {
		jQuery(this).toggleClass("sharepricebtn_f2");
	});
	jQuery("form input.button").live("mouseover mouseout focus blur", function() {
		jQuery(this).toggleClass("button_f2");
	});


	jQuery("form input[type='image']").live('mouseover focus', function(event) {
		jQuery(this).attr('src', jQuery(this).attr('src').split('_f1').join('_f2'));
	}).live('mouseout blur', function(event) {/*mouseout*/
		jQuery(this).attr('src', jQuery(this).attr('src').split('_f2').join('_f1'));
	});

	jQuery("input[type=text],textarea").bind('focus',function() {  // only remove text if the text has not changed
	  if(this.value == this.defaultValue) {
		 $(this).val('');
	  }
	});	
   
	
	jQuery.preloadImages = function()
		{
		  for(var i = 0; i<arguments.length; i++)
		  {
			jQuery("<img>").attr("src", arguments[i]);
		  }
		}
		
		
		
		
		jQuery("a.backtotop").live("click", function() {	
		
			jQuery('html,body').animate({scrollTop: $("#sitewrapper").offset().top},'slow');
		
			return false;											
		});
		
		jQuery("a[rel='printpage']").live("click", function() {	
			window.print();
			return false;											
		});
});	
// --------------------------------------
// --- DOWNLOAD KIT SELECT ALL BUTTON ---
// --------------------------------------

$("input.checkall").live("click", function() {
	$(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
});

// --------------------------------------
// --- PRESENTATIONS POPUP ---
// --------------------------------------
var _POPUP_FEATURES = 'location=0,statusbar=0,menubar=0,width=773,height=600';

function raw_popup(url, target, features) {
if (features ==""){
	theFeatures = _POPUP_FEATURES;
}else{
	theFeatures = features
}
var theWindow = window.open(url, target, theFeatures);
theWindow.focus();
return theWindow;
}

function link_popup(src, target, features) {
	return raw_popup(src, target, features);
}

//get page params for web mets
function getParameterByName(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
	return "";
  else
	return results[1];
}


