
jQuery(document).ready(function($) {
    var newHash      = "",
        $mainContent = $("#main-content"),
        $pageWrap    = $("#page-wrap"),
        baseHeight   = 0,
        $el;
	var prev_hash="";
        
    $pageWrap.height($pageWrap.height());
    baseHeight = $pageWrap.height() - $mainContent.height();
    
	
	
	$('.nav').click(function(event) {//alert($(this).attr("href"));
		window.location.hash = $(this).attr("href");
		change();
		return false;
	});
	
	$('.selected').hide();
    
   /* $(window).bind('hashchange', function(){*/
 function change(){
        newHash = window.location.hash.substring(1);
       
        if (newHash) {
            $mainContent
                .find("#guts")
                .fadeOut(200, function() {
                    $mainContent.hide().load(newHash + " #guts", function() {
                        $mainContent.fadeIn(200, function() {
                            $pageWrap.animate({
                                height: baseHeight + $mainContent.height() + "px"
                            });
                        });
                       /* $("nav a").removeClass("current");
                        $("nav a[href="+newHash+"]").addClass("current");*/
						if(prev_hash)
							$("#"+ prev_hash.replace('.php','') ).show();
						if($("#"+ newHash.replace('.php','')).size()<=0)
							newHash = prev_hash;
						$('.selected').hide();
						$("#"+ newHash.replace('.php','') +"_s").show();
						
						$("#"+ newHash.replace('.php','') ).hide();
						
						 if( window.location.hash.indexOf('faq')>=0){
							run_faq();//run own scripts
						 } else if( window.location.hash.indexOf('form')>=0){
							addDate();//run own scripts
							
						 }else if( window.location.hash.indexOf('remit')>=0){
							run_remit();//run own scripts
						 }
						 prev_hash = newHash;
						 run_face();
						 if(document.getElementById('from_currency')){
							filterFrom();
							updateFees(document.getElementById('from_currency'));	
						}
						$('.nav').unbind('click');
						$('.nav').click( function() {
							window.location.hash = $(this).attr("href");
							change();
							return false;
						});
                    });
                });
			
        };
		
        
    }/*);*/
    
	
	 if( window.location.href.indexOf('faq')>=0){
		run_faq();//run own scripts
	 }else if( window.location.href.indexOf('form')>=0){
		addDate();//run own scripts
	 } else if( window.location.href.indexOf('remit')>=0){
		run_remit();//run own scripts
	 }
	var sPath = window.location.pathname
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	if(!sPage)sPage="index";
	$("#"+ sPage.replace('.php','') +"_s").show();
	$("#"+ sPage.replace('.php','') ).hide();
	prev_hash = sPage;
    $(window).trigger('hashchange');

	if(document.getElementById('from_currency')){
		filterFrom();
		updateFees(document.getElementById('from_currency'));	
	}
});
