﻿//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
	setInterval("checkAnchor()", 300);
});
var currentAnchor = null;
var ClassLink = "";
function checkAnchor() {    
    if (currentAnchor != document.location.hash) {
        currentAnchor = document.location.hash;
        
        if (!currentAnchor) {                
            query = "CH";
        }
        else {
                     
			//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2
            var splits = currentAnchor.substring(1).split('&');
            //Get the section
            var section = splits[0];
            delete splits[0];
            //Create the params string
            var params = splits.join('&');
            var query = "section=" + section + params;

	
			document.getElementById("banner").src = "banner/" + section + ".jpg";
			$("#Content").hide(500);
			setTimeout("showPage('"+section+"','"+query+"')", 500);
			
			if (ClassLink != "")
			{
				$("#" + ClassLink + "_Link").removeClass("active");
				$("#" + section + "_Link").addClass("active");
				ClassLink = section;
			}
			else
			{
				$("#" + section + "_Link").addClass("active");
				ClassLink = section;
			}
        }        
	}
}

function showPage(section,query){
	$.ajaxSetup({ cache: false });
			$("#Content").empty().html('<div style="text-align:center;"><br /><br /><br /><br />'
										+'<br /><img src="images/ajax-loader.gif" algin="center" /></div>');
            $.get(section + ".html", query, function (data) {
				$("#Content").html(data);
												
				
				$("#Content").show(500);
				
			});	
	
}

var Ads_Pre = "Ads_1";
function Change(image, Ads_ID) {
    if (Ads_ID != Ads_Pre) {
        document.getElementById("AdsImage").src = "http://www.omantel-yellowpages.com/images/ads/" + image;

        document.getElementById(Ads_ID).setAttribute("class", "counter1");
        document.getElementById(Ads_ID).style.color = "#000000";


        document.getElementById(Ads_Pre).setAttribute("class", "counter");
        document.getElementById(Ads_Pre).style.color = "#838383";

        Ads_Pre = Ads_ID;
    }
}
