$(function(){

	$("#button").button();
	$("#radioset").buttonset();

	// Accordion
	$("#accordion").accordion({ header: "h3" });
	
	// Tabs
	$('#tabs').tabs();

	// Dialog			
	$('#dialog').dialog({
		autoOpen: false,
		width: 600,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
			}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
			} 
		}
	});
				
	// Dialog Link
	$('#dialog_link').click(function(){
		$('#dialog').dialog('open');
		return false;
	});

	// Datepicker
	$('#datepicker').datepicker({
		inline: true
	});
				
	// Slider
	$('#slider').slider({
		range: true,
		values: [17, 67]
	});
				
	// Progressbar
	$("#progressbar").progressbar({
		value: 70
	});
				
	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
	
});
$(document).ready(function () {
	
	getPage();
	
	//Check if url hash value exists (for bookmark)
	$.history.init(pageload);	
	    
	//highlight the selected link
	$('a[href=' + document.location.hash + ']').addClass('selected');
	
	//Seearch for link with REL set to ajax
	$('a[rel=ajax]').click(function () {
		
		//grab the full url
		var hash = this.href;
		
		//remove the # value
		hash = hash.replace(/^.*#/, '');
		
		//for back button
	 	$.history.load(hash);	
	 	
	 	//clear the selected class and add the class class to the selected link
	 	$('a[rel=ajax]').removeClass('selected');
	 	$(this).addClass('selected');
	 	
	 	//hide the content and show the progress bar
	// 	$('#content').hide();
	 //	$('#loading').show();
	 	
	 	//run the ajax
		getPage();
	
		//cancel the anchor tag behaviour
		return false;
	});	
});
function pageload(hash) {
	//if hash value exists, run the ajax
	if (hash) getPage();    
}
		
function getPage() {
	
	//generate the parameter for the php script

	if (document.location.hash=='') var data = 'p=' + encodeURIComponent('#main');
	else var data = 'p=' + encodeURIComponent(document.location.hash);

	$.ajax({
		url: "loader.php",	
		type: "GET",		
		data: data,		
		cache: false,
		success: function (html) {	
		
			//hide the progress bar
		//	$('#loading').hide();	
			
			//add the content retrieved from ajax and put it in the #content div
			$('#content').html(html);
			
			//display the body with fadeIn transition
			$('#content').fadeIn('slow');		
		}		
	});
}
function aj(DIV,URL,qryString){
	$.ajax({
		type: "GET",
		url: URL,
		data: qryString,
		success: function(message) {
			if (message.length > 0) { $("#"+ DIV).html(message); }
		},
		error: function (xhr, ajaxOptions, thrownError){
			alert(xhr.status+': '+xhr.statusText+'\n'+URL);
		}
	});
}
function aj_post(f,DIV,URL){
	var qryString = $(f).serialize();
	$.ajax({
		type: "POST",
		url: URL,
		data: qryString,
		success: function(message) {
			if (message.length > 0) { $("#"+ DIV).html(message); }
		},
		error: function (xhr, ajaxOptions, thrownError){
			alert(xhr.status+': '+xhr.statusText+'\n'+URL);
		}
	});
}
function aj_post_raw(f,DIV,URL,NOTEDIV){
	var qryString = $(f).serialize();
	$.ajax({
		type: "POST",
		url: URL,
		data: qryString,
		success: function(message) {
			$("#"+NOTEDIV).show();
			$('#'+NOTEDIV).fadeOut(5000);
		},
		error: function (xhr, ajaxOptions, thrownError){
			alert(xhr.status+': '+xhr.statusText+'\n'+URL);
		}
	});
}
function loading_bar(div){
	$(div).html('<br/><center><b>Loading Data. Please Wait...<br/><img src="/images/loading_bar.gif" width="350" /></center><br/>');
}
function pf(where,comment){
   var title = "";
   $.prettyPhoto.open(where, title, comment);
}

function progression_toggle(b,c){$.ajax({type:"GET",url:"scripts/various.php",data:"case=prog_toggle&type="+b+"&pid="+c,success:function(a){$("#"+b+"_"+c).html(a)},error:function(a){alert(a.status+": "+a.statusText+"\n"+URL)}})};
function delAward(b){confirm("Delete this award? There is no undoing this.")&&$.ajax({type:"GET",url:"scripts/various.php",data:"case=DEL_AWARD&LID="+b,success:function(a){a=="1"?$("#tdlid"+b).fadeOut(1E3):alert(a)},error:function(a){alert(a.status+": "+a.statusText+"\nscripts/various.php")}})};
function addAward(b,c,d){$.ajax({type:"GET",url:"scripts/various.php",data:"case=ADD_AWARD&LID="+c+"&name="+d,success:function(a){a.length>0?$("#"+b).html(a):alert(a)},error:function(a){alert(a.status+": "+a.statusText+"\nscripts/various.php")}})};
