jQuery.noConflict();

jQuery(document).ready(function () {
	
	//Check if url hash value exists (for bookmark)
	jQuery.history.init(pageload);
	    
	//highlight the selected link
	jQuery('a[href=' + document.location.hash + ']').addClass('active');
	
	//Seearch for link with REL set to ajax
	jQuery('a[rel=home]').click(function () {
		
		//grab the full url
		var hash = this.href;
		
		//remove the # value
		hash = hash.replace(/^.*#/, '');
		
		//for back button
	 	jQuery.history.load(hash);	
	 	
	 	//clear the selected class and add the class class to the selected link
	 	jQuery('a[rel=home]').removeClass('active');
	 	jQuery(this).addClass('active');
	 	
		//hide the content and show the progress bar
	 	jQuery('#main_content').hide();
		jQuery('#right_panel').hide();
	 	jQuery('#loading').show();
	 	jQuery('#right_loading').show();
		
	 	//run the ajax
		getPage(hash);
		getsubPage(hash);
	
		//cancel the anchor tag behaviour
		return false;
	});	

});
	
	function callpage(hash) {
		
		//remove the # value
		hash = hash.replace(/^.*#/, '');
		
		//for back button
	 	jQuery.history.load(hash);
	 	
	 	//clear the selected class and add the class class to the selected link
	 	jQuery('a[rel=sub_link]').removeClass('active');
	 	jQuery(this).addClass('active');

		//hide the content and show the progress bar
	 	jQuery('#main_content').hide();
		jQuery('#right_panel').hide();
	 	jQuery('#loading').show();
	 	jQuery('#right_loading').show();
	 	//run the ajax

		getPage(hash);
		getsubPage(hash);

	}	

function pageload(hash) {
	//if hash value exists, run the ajax

if (hash) { 
			if(jQuery.browser.msie) {
	hash = encodeURIComponent(hash);
			}
	
	} else { 
	hash='inbox'; 
	}

	getPage(hash);
	getsubPage(hash);
	
}
		

function getPage(hash) {
	
	//generate the parameter for the php script
	var data = 'page=' + encodeURIComponent(hash);
	jQuery.ajax({
		url: "panel_main_beta.php",	
		type: "GET",		
		data: data,		
		cache: false,
		success: function (html) {	
		
			//hide the progress bar
			jQuery('#loading').hide();	
			
			//add the content retrieved from ajax and put it in the #content div
			jQuery('#main_content').html(html);
			
			//display the body with fadeIn transition
			jQuery('#main_content').fadeIn('slow');		
		}		
	});
}
function getsubPage(hash) {
	
	//generate the parameter for the php script
	var data = 'page=' + encodeURIComponent(hash);
	jQuery.ajax({
		url: "panel_left_beta.php",	
		type: "GET",		
		data: data,		
		cache: false,
		success: function (html) {	
		
			//hide the progress bar
		 	jQuery('#right_loading').hide();

			//add the content retrieved from ajax and put it in the #right_panel div
			jQuery('#right_panel').html(html);

			//display the #right_panel with fadeIn transition
			jQuery('#right_panel').fadeIn('slow');		
		}		
	});
}
