//var site_root = "http://192.168.10.3/newcastle_futures/";
//var site_root = "http://nfutures.fuseboxhosting.co.uk/";
var site_root = "http://www.newcastlefutures.co.uk/";

/* Make links where they have rel="external" in them open in a new window */		
document.onclick = function(e)
{
	var target = e ? e.target : window.event.srcElement;    
	while (target && !/^(a|body)$/i.test(target.nodeName))
	{
		target = target.parentNode;
	}
	
	if (target && target.getAttribute('rel') && target.rel == 'external')
	{
		var external = window.open(target.href);
		return external.closed;
	}
}

$(document).ready(function(){

	jQuery.fn.fadeToggle = function(){
		return this.animate({opacity:'toggle'});
	};
	
	setTimeout('$("div.alert_success").animate({height:\'hide\',opacity:\'hide\'},1500);', 2500);
	setTimeout('$("div.alert_failed").animate({height:\'hide\',opacity:\'hide\'},1500);', 6000);
  
  $("input#search").focus(function(){
      if($(this).val() == "Search")
      {
          $(this).val("");
      }
  });
  
  $("input#search").blur(function(){
      if($(this).val() == "")
      {
          $(this).val("Search");
      }
  });
    
  $('a.open_new_window').click(function(){
		window.open(this.href);
		return false;
  });
  
	$("div.navigation ul li").bind("mouseenter",function(){
    if($.browser.msie){
      $(this).find("ul").show();
    }
    else{
      $(this).find("ul").fadeIn(400);
    }
  }).bind("mouseleave",function(){
    if($.browser.msie){
      $(this).find("ul").hide();
    }
    else{
      $(this).find("ul").fadeOut(400);
    }
  });
      
});

function createCookie(name, value, days)
{
	if(days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
	{
	  var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}
