/*
Code for navigation hover courtesy of Adrian Pelletier
http://www.adrianpelletier.com
*/
// Begin jQuery

$(document).ready(function () {  
      
	// Animate Icons
	$("#navigation li").hover(function() {
		var e = this;
	    $(e).find("a").stop().animate({ marginTop: "-6px" }, 250, function() {
	    $(e).find("a").animate({ marginTop: "-2px" }, 250);
		});
		  
	},function(){
		var e = this;
	    $(e).find("a").stop().animate({ marginTop: "0px" }, 250, function() {
	    	$(e).find("a").animate({ marginTop: "0px" }, 250);
	    });
		  
	});
			
	//get the default content.	
	getPage();  
	   
    //Check if url hash value exists (for bookmark)  
    $.history.init(pageload);     
           
    //Search for link with REL set to page or form  
    $('a[rel=page]').click(function () {  
           
         //grab the full url  
         var hash = this.href;  
      		   
         //remove the # value  
         hash = hash.replace(/^.*#/, '');  
           
         //for back button  
         $.history.load(hash);     
         	
	   	 //show the progress bar
		 $('#loadDiv').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 content = 'home';
	else var content = document.location.hash.replace(/^.*#/, ''); 
  		
	//hide the content	
	$('#content').hide();
			
	$.post("content/content.php",{ sendValue: content },
			function(data){
			document.getElementById("content").innerHTML = data.returnValue;
			}, "json");
			
	//hide the progres bar and display the content with fadeIn transition  
	$('#loadDiv').hide();
	$('#content').fadeIn('slow'); 	
}   

 function getPage2(content) {  
    	 
	//for back button  
    $.history.load(content);  
		 
	//hide the content	
	$('#content').hide();
			
	$.post("content/content.php",{ sendValue: content },
			function(data){
			document.getElementById("content").innerHTML = data.returnValue;
			}, "json");
			
	//hide the progres bar and display the content with fadeIn transition  
	$('#loadDiv').hide();
	$('#content').fadeIn('slow'); 	
} 

//shows a text editor when the site administrator is logged in and clicks on the content to be edited.
function getEditor () {

	$('#nonEdit').hide();
	$('#edit').fadeIn('slow');

}

//displays a colour picker in the colourpicker div. 
function colourPicker () {
	$('#colorpicker').farbtastic('#color');
}  

//change HEX to rgb
function hexToRgb($hexColour)
{
R = HexToR($hexColour);
G = HexToG($hexColour);
B = HexToB($hexColour);

function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}

$rgbColour = R + G + B;
   alert ($rgbColour);
 }




//preload images
function myPreload()	{
		
			var a = new Array;
			a[0]="images/loginbutton2.png";
			a[1]="images/logoutbutton2.png";
			a[2]="images/forgottenbutton2.png";
			a[3]="images/announcebutton2.png";
			a[4]="images/blogbutton2.png";
			a[5]="images/cancelbutton2.png";
			a[6]="images/deletebutton2.png";
			a[7]="images/groupbutton2.png";
			a[8]="images/imagesbutton2.png";
			a[9]="images/memdetailsbutton2.png";
			a[10]="images/submitbutton2.png";
			a[11]="images/viewmembutton2.png";
			a[12]="images/loading.gif";
			a[13]="images/confirmbutton2.png";
			a[14]="images/corganiserbutton2.png";
			a[15]="images/eannouncebutton2.png";
			a[16]="images/eeventsbutton2.png";
			a[17]="images/joinbutton2.png";
			a[18]="images/nlinkbutton2.png";
			a[19]="images/linksbutton2.png";
			a[20]="images/nannouncebutton2.png";
			a[21]="images/neventbutton2.png";
			a[22]="images/updatebutton2.png";
			a[23]="images/uploadbutton2.png";
			a[24]="images/veventsbutton2.png";
			a[25]="images/lbutton2.png";
			a[26]="images/deleteicon2.png";
			a[27]="images/editicon2.png";
			a[28]="images/registerbutton2.png";
			a[29]="images/attendeesicon2.png";
			
			var b = new Array();
			for (i = 0; i < a.length; i++)	{
			b[i] = new Image();
			b[i].src = a[i];
			}
		
}

//IMAGE SRC HOVER USING THIS 

function onHover(location)	{
				location.src = "images/" + location.name + "2.png";
}
			
function onExit(location)	{
				location.src = "images/" + location.name + ".png";
} 

//IMAGE BACKGROUND HOVER USING THIS 

function onHover2(location)	{

				document.getElementById(location.id).style.background = "url(images/" + location.name + "2.png)";
}
			
function onExit2(location)	{
				document.getElementById(location.id).style.background = "url(images/" + location.name + ".png)";
}  
