$(function() {

    setTimeout(
		function() {
	$('.tip_trigger').each(function() {        
        var tip = $(this).find('.tip');

        $(this).hover(
            function(){tip.appendTo('body').hide().fadeIn(500);	},
            function(){ tip.hide();tip.appendTo(this); }
        ).mousemove(function(e) {
            var x = e.pageX + 20,
                y = e.pageY + 20,
                w = tip.width(),
                h = tip.height(),
                dx = $(window).width() - (x + w),
                dy = $(window).height() - (y + h);

            if ( dx < 20 ) x = e.pageX - w - 20;
            if ( dy < 20 ) y = e.pageY - h - 20;

            tip.css({ left: x, top: y });
        });         
    });
    
    $('.boxgrid').each(function() {        
        var tip = $(this).find('.tip');

        $(this).hover(
            function() { tip.appendTo('body'); },
            function() { tip.appendTo(this); }
        ).mousemove(function(e) {
            var x = e.pageX + 20,
                y = e.pageY + 20,
                w = tip.width(),
                h = tip.height(),
                dx = $(window).width() - (x + w),
                dy = $(window).height() - (y + h);

            if ( dx < 20 ) x = e.pageX - w - 20;
            if ( dy < 20 ) y = e.pageY - h - 20;

            tip.css({ left: x, top: y });
        });         
    }); 
	}, 2600);

});

function stagei(str)
{
	if (str=="")
	{
		document.getElementById("box product3").innerHTML="";
		document.getElementById("box product4").innerHTML="";
		return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("box product3").innerHTML=xmlhttp.responseText;
			document.getElementById("box product4").innerHTML="";
			document.getElementById("box product5").innerHTML="";
			document.getElementById("box product9").innerHTML="";
			$(".product3 h3").hide();
			$(".product3 h3").slideDown(400);
		}
	}
	xmlhttp.open("GET","/Mods/getcountry.php?p="+str,true);
	xmlhttp.send();
}

function clear_stagei(obj)
{
	$(".product2 h3").animate({ backgroundColor: "#ffffff" }, 300);
	jQuery('h3', obj).animate({ backgroundColor: "#BCBDC1" }, 300);
}

function stageii(str)
{
	if (str=="")
	{
		document.getElementById("box product4").innerHTML="";
		return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("box product5").innerHTML="";
			document.getElementById("box product9").innerHTML="";
			document.getElementById("box product4").innerHTML=xmlhttp.responseText;
			refresh_address();
		}
	}
	xmlhttp.open("GET","/Mods/getcompany.php?p="+str,true);
	xmlhttp.send();
}

function clear_stageii(obj)
{
	$(".product3 h3").animate({ backgroundColor: "#ffffff" }, 300);
	jQuery('h3', obj).animate({ backgroundColor: "#BCBDC1" }, 300);	
}

function stageee(str)
{
if (str=="")
  {
  document.getElementById("box product4").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	document.getElementById("box product5").innerHTML="";
	document.getElementById("box product4").innerHTML="";
    document.getElementById("box product9").innerHTML=xmlhttp.responseText;
	$(".product9 h3").hide();
	$(".product9 h3").slideDown(400);
	refresh_address();
    }
  }
xmlhttp.open("GET","/Mods/getcounty.php?p="+str,true);
xmlhttp.send();
}

function clear_stageiii(obj)
{
	$(".product9 h3").animate({ backgroundColor: "#ffffff" }, 300);
	jQuery('h3', obj).animate({ backgroundColor: "#BCBDC1" }, 300);	
}

function stageeei(str)
{
if (str=="")
  {
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("box product5").innerHTML=xmlhttp.responseText;
	refresh_address5();
    }
  }
xmlhttp.open("GET","/Mods/getcompany.php?pi="+str,true);
xmlhttp.send();
}

function clear_stageeei(obj)
{
	$(".product5 h3").animate({ backgroundColor: "#ffffff" }, 300);
	jQuery('h3', obj).animate({ backgroundColor: "#BCBDC1" }, 300);
}

function refresh_address()
{
	$(".product4 h3").hide();
	$(".product4 p").hide();
	$(".product4 h3").slideDown(400);	
	$(".product4 h3").click(function()
	{
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$('.active').animate({ backgroundColor: "#ffffff" }, 1000);
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
		$('.active').animate({ backgroundColor: "#BCBDC1" }, 1000);
	});
}

function refresh_address5()
{
	$(".product5 h3").hide();
	$(".product5 p").hide();
	$(".product5 h3").slideDown(400);	
	$(".product5 h3").click(function()
	{
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$('.active').animate({ backgroundColor: "#ffffff" }, 1000);
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
		$('.active').animate({ backgroundColor: "#BCBDC1" }, 1000);
	});
}
