$.easy.navigation('#mainnav li');
/**
 * Returns an array with all the url vars
 * @return array The array of url vars in the format: array['var_name']['var_value']
 */
function getUrlVars(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

  /*  Cufon.replace("h1, h2, h3, #subnav .tab a, ul#mainnav li.root a, .subheader, th, u, #footer .bottom_nav, #extra .latest_news h1", {
        fontFamily: 'Adobe Garamond Pro'
    });*/ 
	
   /* Cufon.replace(".showhome_link, .links .text", {
        fontFamily: 'Silvero'
    });
*/

$(document).ready(function(){
	$.easy.forms();
	$.easy.tooltip();

$('#subnav ul').fadeOut(0);


    	
	//spread Navigation
	
		var sum = 0, num = 0;
		var total = $('#nav').width() - 15;
		
		$('#mainnav li.root').each(function() {
			sum += $(this).width();
			num++;
		});
		var extra = (total-sum) / num;
		
		$('#mainnav li.root').each(function() {
			//$(this).width(parseInt($(this).width())+extra);
		});
		
		    var _GET = getUrlVars();
    
   //$('#mainnav').superfish();
    
    //Resize Tabs 
    var total_size = $('#subnav').width();
    
    $('#tabs li').each(function(){
        var width = $(this).width();
		var text_length = $(this).children().eq(0).text().length;
		width = 10 * text_length;
        $(this).width(width+50);
    });
    
    var calc_tables_width = $('.tables').width();
    $('#charts').width(calc_tables_width);
    
  
    
    //Fancybox
    /* This is basic - uses default settings */
    $("a#single_image").fancybox();
    
    /* Using custom settings */
    
    $("a#inline").fancybox({
        'hideOnContentClick': true
    });
    
    /* Apply fancybox to multiple items */
    
    $("a.group").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': false
    });
    
    $("a.fancybox").fancybox();
    
    
    if (screen.width <= 1024) {
        $('#page').width($(window).width());
        //$('#inner').css("padding-left", parseInt($('#inner').width()))
    }
    
    var content = parseInt($('#content').height());
    var header = parseInt($('#header').height());
    var footer = parseInt($('#footer').height());
    
    if (parseInt(content + header + footer) < parseInt($(window).height())) {
        var diff = parseInt($(window).height()) - parseInt(content + header + footer);
        //$('#content').height(content + diff)
    }
    
    
    $('.data').each(function(){
        $(this).hide();
        if ($(this).attr("name") == 0) 
            $(this).show();
    });
    
    
    
	
    if (_GET['sp'] == null) {
        $('#tabs li a').eq(0).addClass("selected");
        $('#tabs li').eq(0).children().css("visibility", "visible");
		if (_GET['p'] == null) {
			
			contentSwitch(1);
		}
		else 
			contentSwitch(_GET['p']);
		
		
    }
    else {
    
        $('#tabs li a').eq(parseInt(_GET['sp'])).addClass("selected");
        $('#tabs li').eq(parseInt(_GET['sp'])).children().css("visibility", "visible");
		contentSwitch(_GET['sp']);
		$('li.tab[name='+_GET['sp']+'] a').addClass("selected");
		$('li.tab[name='+_GET['sp']+']').children().css("visibility", "visible");
		
    }
    
    $('#tabs li a').each(function(){
        $(this).click(function(){
			
            var page_id = $(this).parent().attr("name");
			
			contentSwitch(page_id);
            
             
             	$('#subnav li a').removeClass("selected");
             	$('#subnav li').children('.img').css("visibility", "hidden");
             
             
             $(this).addClass("selected");
             $(this).parent().children('.img').css("visibility", "visible");
             
             
        });
    });
    
 
/*
    $('input, textarea').each(function(){
        if ($(this).attr("name") != "submit" && $(this).attr("value") != "Search") {
            $(this).click(function(){
                if (parseInt($(this).attr("alt")) != 1) {
                    $(this).val("");
                    $(this).html("");
                    $(this).attr("alt", 1);
                }
            });
        }
    });
    */
	
	$('#subnav ul').fadeIn(1500);
	
});

   function contentSwitch(page_id){
    	
        $('.data').each(function(){
            //$(this).hide();
			$(this).attr("style", "display: inline;");
            if ($(this).attr("name") != page_id) {
				$(this).attr("style", "display: none;");
				var height = $(this).height();
				//$('#footer').css("position", "relative");
			}
        });
        
      
    }
    
	function layoutHeight(){
		var content = parseInt($('#content').height());
		var header = parseInt($('#header').height());
		var footer = parseInt($('#footer').height());
		
		if (parseInt(content + header + footer) < parseInt($(window).height())) {
			var diff = parseInt($(window).height()) - parseInt(content + header + footer);
			//$('#content').height(content + diff);
			
		}
	}
	
	

