document.createElement("footer");
document.createElement("header");




var globarflag = false;
var current;
var ttcurrent = new Array();

    var bgImages = [ 'slide/home1.jpg','slide/home2.jpg','slide/home3.jpg','slide/home4.jpg' ];
    var currImage = 'slide/home3.jpg';
var contador=1;

$( function(){

    setInterval( function(){ 
		if (globarflag) return; 
		 
         //var randImage = bgImages[contador];
		 if (contador  == 0) {
			randImage = 'slide/home1.jpg';	
			$('#menu-headermain').css('backgroundImage', 'url(slide/home1.jpg)');
			//$('#menu-headermain').css({backgroundImage:"url(slide/home1.jpg)"});
//			$(randImage).fadeOut('slow', function() {
//        			// Animation complete
//      				});
		     }
		 if (contador  == 1) {
			randImage = 'slide/home2.jpg';
			$('#menu-headermain').css({backgroundImage:"url(slide/home2.jpg)"});
//			$(randImage).fadeOut('slow', function() {
//        			// Animation complete
//      				});
		}
		if (contador  == 2) {   
			randImage = 'slide/home3.jpg';	
			$('#menu-headermain').css('backgroundImage', 'url(slide/home3.jpg)');
			//$('#menu-headermain').css({backgroundImage:"url(slide/home3.jpg)"});
//			$(randImage).fadeOut('slow', function() {
//        			// Animation complete
//      				});
		}
		if (contador  == 3) {
			randImage = 'slide/home4.jpg';
			$('#menu-headermain').css({backgroundImage:"url(slide/home4.jpg)"});
//			$(randImage).fadeOut('slow', function() {
//        			// Animation complete
//      				});
		}
		contador++;	 
		if(contador>3) contador =0;
		 currImage = randImage
       // $('#menu-headermain').BgImageTransition( randImage );  
		mainmenu();
    }, 5000)
})


function mainmenu()
{
// Oculto los submenus
	$(" #menun ul ul ").css({display: "none"});
 //Defino que submenus deben estar visibles cuando se pasa el mouse por encima
 	$(" #menun ul li ul li").hover( function() {
											 globarflag = true;
											$(this).css({ backgroundImage : "url(images/arrowblack.png)" });
											if ($(this).attr('id') == "primero") {
												$(this).css({ backgroundPosition : "0px 9px" });
											}
											 },
											 function() {
												 globarflag = false;
												 $(this).css({ backgroundImage : "url(images/black.png)" });
											 }
											 
											 
											 );
	$(" #menun ul li").hover(function(){ 
									  globarflag = true;
									  //clearTimeout(ttcurrent[$(this).attr("id")]);
   										$(this).find('ul:first:hidden').css({visibility: "visible",display: "none"}).slideDown(400);
 	},function(){
		 
		 current = $(this).find('ul:first');
	ttcurrent[$(this).attr("id")] = setTimeout(function() {
						globarflag = false;
						current.css( {visibility:"hidden"} ); 
						}, 290);
  	$(this).find('ul:first').slideUp(300, function() { 
												   globarflag = false;
												   $(this).css( {display: "none", visibility: "hidden" } );
												   });
});
	
	
	
	
	
	
	$(" .menun ul ul ").css({display: "none"});
 //Defino que submenus deben estar visibles cuando se pasa el mouse por encima
 	$(" .menun ul li ul li").hover( function() {
											
											 globarflag = true;
											$(this).css({ backgroundImage : "url(images/arrowblack.png)" });
											if ($(this).attr('id') == "primero") {
												$(this).css({ backgroundPosition : "0px 9px" });
											}
											 },
											 function() {
												 globarflag = false;
												 $(this).css({ backgroundImage : "url(images/black.png)" });
											 }
											 
											 
											 );
	$(" .menun ul li").hover(function(){ 
									  globarflag = true; 
									  //clearTimeout(ttcurrent[$(this).attr("id")]);
   										$(this).find('ul:first:hidden').css({visibility: "visible",display: "none"}).slideDown(400);
 	},function(){
		 
		 current = $(this).find('ul:first');
	ttcurrent[$(this).attr("id")] = setTimeout(function() {
						globarflag = false;
						current.css( {visibility:"hidden"} ); 
						}, 290);
  	$(this).find('ul:first').slideUp(300, function() { 
												   globarflag = false;
												   $(this).css( {display: "none", visibility: "hidden" } );
												   });
});
	
	
}

setTimeout(function() {
	$("#t1").css("opacity", 0).css("paddingLeft", "200px").animate( {
					 paddingLeft:"100px",
					 opacity: 1
					 }, 900, 'swing', function () {
						 //do nothing
						 } );
	$("#t2").css("opacity", 0).css("paddingLeft", "0px").animate( {
					 paddingLeft:"100px",
					 opacity: 1
					 }, 900, 'swing', function () {
						 //do nothing
						 } );
	$("#t3").css("opacity", 0).css("paddingLeft", "150px").animate( {
					 paddingLeft:"100px",
					 opacity: 1
					 }, 900, 'swing', function () {
						 //do nothing
						 } );
						}, 1000);

function showelements1(){
		$('#content1').fadeIn('normal');
	}
	function showelements2(){
		$('#content2').fadeIn('normal');
	}
	function showelements3(){
		$('#content3').fadeIn('normal');
	}
	function showelements4(){
		$('#content4').fadeIn('normal');
	}
	function showelements5(){
		$('#content5').fadeIn('normal');
	}
	function showelements6(){
		$('#content6').fadeIn('normal');
	}
$(document).ready(function() {
	imagePreview();
	imagePreview1();
	imagePreview2();
	imagePreview3();
    mainmenu();

	$("#t1").css("opacity", 0);
	$("#t2").css("opacity", 0);
	$("#t3").css("opacity", 0);
	
	$('#energy').click(function(){
		hideelements1();
		var t=setTimeout("showelements1()",600);
	});
	$('#growth').click(function(){
		hideelements2();
		var t=setTimeout("showelements2()",600);
		//$('#content2').delay(15000).fadeIn('normal');
	});
	$('#wealth').click(function(){
		hideelements3();
		var t=setTimeout("showelements3()",600);
	});
	$('#demographics').click(function(){
		hideelements4();
		var t=setTimeout("showelements4()",600);
	});
	$('#debt').click(function(){
		hideelements5();
		var t=setTimeout("showelements5()",600);
	});
	$('#secondary').click(function(){
		hideelements6();
		var t=setTimeout("showelements6()",600);
	});
	/*$('#energy').click(function(){
		$('#content1').show('normal',hideelements1());
	});
	$('#growth').click(function(){
		$('#content2').show('normal',hideelements2());
	});
	$('#wealth').click(function(){
		$('#content3').show('normal',hideelements3());
	});
	$('#demographics').click(function(){
		$('#content4').show('normal',hideelements4());
	});
	$('#debt').click(function(){
		$('#content5').show('normal',hideelements5());
	});
	$('#secondary').click(function(){
		$('#content6').show('normal',hideelements6());
	}); */
	/*function showelements1(){
		$('#content1').fadeIn('normal');
	}
	function showelements2(){
		$('#content2').fadeIn('normal');
	}
	function showelements3(){
		$('#content3').fadeIn('normal');
	}
	function showelements4(){
		$('#content4').fadeIn('normal');
	}
	function showelements5(){
		$('#content5').fadeIn('normal');
	}
	function showelements6(){
		$('#content6').fadeIn('normal');
	}*/
	function hideelements1(){		
	 
		$('#content2').fadeOut('slow');
		$('#content3').fadeOut('slow');
		$('#content4').fadeOut('slow');
		$('#content5').fadeOut('slow');
		$('#content6').fadeOut('slow'); 
	}
	function hideelements2(){		
		$('#content1').fadeOut('slow');
		$('#content3').fadeOut('slow');
		$('#content4').fadeOut('slow');
		$('#content5').fadeOut('slow');
		$('#content6').fadeOut('slow');
	}
	function hideelements3(){		
		$('#content1').fadeOut('slow');
		$('#content2').fadeOut('slow');
		$('#content4').fadeOut('slow');
		$('#content5').fadeOut('slow');
		$('#content6').fadeOut('slow');
	}
	function hideelements4(){		
		$('#content1').fadeOut('slow');
		$('#content2').fadeOut('slow');
		$('#content3').fadeOut('slow');
		$('#content5').fadeOut('slow');
		$('#content6').fadeOut('slow');
	}
	function hideelements5(){		
		$('#content1').fadeOut('slow');
		$('#content2').fadeOut('slow');
		$('#content3').fadeOut('slow');
		$('#content4').fadeOut('slow');
		$('#content6').fadeOut('slow');
	}
	function hideelements6(){		
		$('#content1').fadeOut('slow');
		$('#content2').fadeOut('slow');
		$('#content3').fadeOut('slow');
		$('#content4').fadeOut('slow');
		$('#content5').fadeOut('slow');
	}
	
});


var lastp1;
var lastp2;

this.imagePreview = function(){  
  xOffset = 10;
  yOffset = 30; 
 $("a.preview").hover(function(e){
							   
  this.t = this.title;
  this.title = ""; 
  var c = (this.t != "") ? "<br/>" + this.t : "";
  $("body").append("<div id='preview'><img src='images/chapet-titulo.png'   />"+ c +"</div>");     
  $("body").append("<div id='preview_alt'><img src='images/Chapel_hill.png'  alt='Image preview' />"+ c +"</div>");
  
  $("#preview")
   .css("top",(e.pageY - xOffset) + "px")
   .css("left",(e.pageX + yOffset) + "px")
   .fadeIn("fast");   
   
  $("#preview_alt")
   .css("top",(e.pageY - xOffset + 16) + "px")
   .css("left",(e.pageX + yOffset - 163) + "px")
   .fadeIn("fast");   
    
		if (lastp1 != null) { 
						if (lastp1 ==  $("#preview")) return;
			lastp1.remove();
			lastp2.remove();
		}
  		lastp1  =  $("#preview");
		lastp2  =  $("#preview_alt");
		$("#pt1").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 1);
		$("#pt2").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 2);
		$("#pt3").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 3);
		$("#pt4").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 4);
  			 
    }, 
 function(){
	
  this.title = this.t; 
  $("#preview").remove(); 
  
  $("#preview_alt").remove();
  
  }); 
 
 $("a.preview").mousemove(function(e){
	return;							   
  $("#preview")
   .css("top",(e.pageY - xOffset - 25) + "px")
   .css("left",(e.pageX + yOffset - 100) + "px");
  $("#preview_alt")
  	.css("top",(e.pageY - xOffset + 16) + "px")
   	.css("left",(e.pageX + yOffset - 163) + "px");
   
   
 }); 
 
}; 
this.imagePreview1 = function(){  
  xOffset = 10;
  yOffset = 30; 
 $("a.preview1").hover(function(e){
  this.t = this.title;
  this.title = ""; 
  var c = (this.t != "") ? "<br/>" + this.t : "";
  $("body").append("<div id='preview1'><img src='images/New_York_title.png' style='margin-left:70px' />"+ c +"</div>");     
  $("body").append("<div id='preview1_alt'><img src='images/New_York.png' alt='Image preview' />"+ c +"</div>");
  
  $("#preview1")
   .css("top",(e.pageY - xOffset - 25) + "px")
   .css("left",(e.pageX + yOffset - 100) + "px")
   .fadeIn("fast");   
   
  $("#preview1_alt")
   .css("top",(e.pageY - xOffset + 16) + "px")
   .css("left",(e.pageX + yOffset - 153) + "px")
   .fadeIn("fast");  
   
   
   		if (lastp1 != null) {
			if (lastp1 ==  $("#preview1")) return;
			lastp1.remove();
			lastp2.remove();
		}
  		lastp1  =  $("#preview1");
		lastp2  =  $("#preview1_alt");
		$("#pt1").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 1);
		$("#pt2").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 2);
		$("#pt3").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 3);
		$("#pt4").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 4);
   
    },
	 
 function(){
  this.title = this.t; 
  	$("#preview1").remove();
   $("#preview1_alt").remove();
    }); 
 $("a.preview1").mousemove(function(e){
									
									return;
									
  $("#preview1")
   .css("top",(e.pageY - xOffset - 25) + "px")
   .css("left",(e.pageX + yOffset - 100) + "px");
  $("#preview1_alt")
  	.css("top",(e.pageY - xOffset + 16) + "px")
   	.css("left",(e.pageX + yOffset - 153) + "px");
 });   
};




this.imagePreview3 = function(){  
  xOffset = 10;
  yOffset = 30; 
 $("a.preview3").hover(function(e){
  this.t = this.title;
  this.title = ""; 
  var c = (this.t != "") ? "<br/>" + this.t : "";
  $("body").append("<div id='preview2'><img src='images/Beijing-title.png'  />"+ c +"</div>");     
  $("body").append("<div id='preview2_alt'><img src='images/Beijing.png' alt='Image preview' />"+ c +"</div>");
  
  $("#preview2")
   .css("top",(e.pageY - xOffset - 26) + "px")
   .css("left",(e.pageX + yOffset - 52) + "px")
   .fadeIn("fast");   
     $("#preview2_alt")
   .css("top",(e.pageY - xOffset + 14) + "px")
   .css("left",(e.pageX + yOffset -428) + "px")
   .fadeIn("fast");   
   
   
      		if (lastp1 != null) {
			if (lastp1 ==  $("#preview2")) return;
			lastp1.remove();
			lastp2.remove();
		}
  		lastp1  =  $("#preview2");
		lastp2  =  $("#preview2_alt");
   				$("#pt1").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 1);
		$("#pt2").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 2);
		$("#pt3").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 3);
		$("#pt4").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 4);
   
    }, 
	
 function(){
  this.title = this.t; 
  $("#preview2").remove();
     $("#preview2_alt").remove();
    }); 
 $("a.preview3").mousemove(function(e){
									
									return;
									
  $("#preview2")
   .css("top",(e.pageY - xOffset - 26) + "px")
   .css("left",(e.pageX + yOffset - 52) + "px");
  $("#preview2_alt")
  	.css("top",(e.pageY - xOffset + 14) + "px")
   	.css("left",(e.pageX + yOffset -428) + "px");
 });   
};
 
this.imagePreview2 = function(){  
  xOffset = 10;
  yOffset = 30; 
 $("a.preview2").hover(function(e){
  this.t = this.title;
  this.title = ""; 
  var c = (this.t != "") ? "<br/>" + this.t : "";
  $("body").append("<div id='preview3'><img src='images/Hong_Kong_title.png' />"+ c +"</div>");  
  $("body").append("<div id='preview3_alt'><img src='images/Hong_Kong.png' alt='Image preview' />"+ c +"</div>");
  $("#preview3")
   .css("top",(e.pageY - xOffset) + "px")
   .css("left",(e.pageX + yOffset - 20) + "px")
   .fadeIn("fast");   
        $("#preview3_alt")
   .css("top",(e.pageY - xOffset + 12) + "px")
   .css("left",(e.pageX + yOffset -414) + "px")
   .fadeIn("fast");   
      		if (lastp1 != null) {
			if (lastp1 ==  $("#preview3")) return;
			lastp1.remove();
			lastp2.remove();
		}
  		lastp1  =  $("#preview3");
		lastp2  =  $("#preview3_alt");
   
   				$("#pt1").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 1);
		$("#pt2").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 2);
		$("#pt3").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 3);
		$("#pt4").css("z-index", Math.max(parseInt(lastp1.css("z-index")), parseInt(lastp2.css("z-index"))) + 4);
    }, 
 function(){
  this.title = this.t; 
  $("#preview3").remove();
       $("#preview3_alt").remove();
    }); 
 $("a.preview2").mousemove(function(e){
									
									return;
									
  $("#preview3")
   .css("top",(e.pageY - xOffset) + "px")
   .css("left",(e.pageX + yOffset - 20) + "px");
     $("#preview3_alt")
  	.css("top",(e.pageY - xOffset + 12) + "px")
   	.css("left",(e.pageX + yOffset -414) + "px");
 });   
};

var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}
function showhint2(menucontents, obj, e, tipwidth){
	if ((ie||ns6) && document.getElementById("hintbox")){
		dropmenuobj=document.getElementById("hintbox")
		dropmenuobj.innerHTML=menucontents
		dropmenuobj.style.left=dropmenuobj.style.top=-500
		if (tipwidth!=""){
			dropmenuobj.widthobj=dropmenuobj.style
			dropmenuobj.widthobj.width=tipwidth
		}
		dropmenuobj.x=getposOffset(obj, "left")-150
		dropmenuobj.y=getposOffset(obj, "top")+265
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
		dropmenuobj.style.visibility="visible"
		obj.onmouseout=hidetip
	}
}
function hidetip(e){
	dropmenuobj.style.visibility="hidden"
	dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox


/*function mycarousel_itemLastOutCallback(carousel, item, idx, state) {
    //display('Item #' + idx + ' is no longer the last item');

	if(idx == 1){
		$('#comprehensive_button').css('background-position','0 0px');
	}else{
		$('#comprehensive_button').removeAttr('style');
	}
	if(idx == 2){
		$('#complete_button').css('background-position','0 0px');
	}else{
		$('#complete_button').removeAttr('style');
	}
	if(idx == 3){
		$('#public_button').css('background-position','0 0px');
	}else{
		$('#public_button').removeAttr('style');
	}
	if(idx == 4){
		$('#private_button').css('background-position','0 0px');
	}else{
		$('#private_button').removeAttr('style');
	}
};*/
/*$("#comprehensive_button").mouseover(function() {
    $(this).css('background-position','0 -50px');
  }).mouseout(function(){
    $(this).css('background-position','0 0px');
  });
$("#complete_button").mouseover(function() {
    $(this).css('background-position','0 -50px');
  }).mouseout(function(){
    $(this).css('background-position','0 0px');
  });
$("#public_button").mouseover(function() {
    $(this).css('background-position','0 -50px');
  }).mouseout(function(){
    $(this).css('background-position','0 0px');
  });
$("#private_button").mouseover(function() {
    $(this).css('background-position','0 -50px');
  }).mouseout(function(){
    $(this).css('background-position','0 0px');
  });
*/
function change_chart(id,id2){
	var buttons_array=new Array('comprehensive_button','complete_button','public_button','private_button'); 
	var chart_array=new Array('comprehensive_chart','complete_alternative_chart','public_alternative_chart','private_investment_chart'); 
	for(i=0; i < buttons_array.length; i++){
		//document.getElementById(buttons_array[i]).style.backgroundPosition = "0px 0px";
		document.getElementById(chart_array[i]).style.display = "none";
	}
	
	if(id == 'comprehensive_button'){
		//document.getElementById(id).style.backgroundPosition = "0px -61px";
		document.getElementById(id2).style.display = "block";
	}else if(id == 'complete_button'){
		//document.getElementById(id).style.backgroundPosition = "0px -61px";
		document.getElementById(id2).style.display = "block";
	}else if(id == 'public_button'){
		//document.getElementById(id).style.backgroundPosition = "0px -61px";
		document.getElementById(id2).style.display = "block";
	}else if(id == 'private_button'){
		//document.getElementById(id).style.backgroundPosition = "0px -61px";
		document.getElementById(id2).style.display = "block";
	}
}
