$(document).ready(function() {
	
	/********************************************************************************************************************
	SIMPLE ACCORDIAN STYLE MENU FUNCTION
	********************************************************************************************************************/	
	$('div.accordionButton').click(function() {
		$('div.accordionContent').slideUp('normal');	
		$(this).next().slideDown('normal');
	});
	
	/********************************************************************************************************************
	CLOSES ALL DIVS ON PAGE LOAD
	********************************************************************************************************************/	
	$("div.accordionContent").hide();

	// MENU INIT
	jQuery('ul.sf-menu').superfish();
});

function Home(id){
	$("#mainContent").html('<div class="spinner"><img src="img/loader.gif" /></div>');
	$.post("home.php", function(data){
		$("#mainContent").html(data);
	});
	
	return false;
}
function Page(name){
	$("#mainContent").html('<div class="spinner"><img src="img/loader.gif" /></div>');
	$.post(name + ".php", function(data){
		$("#mainContent").html(data);
	});
	
	return false;
}

function changeLanguage(langID){	
    window.location.href = "index.php?lang=" + langID;
}

function isValidEmail(strEmail){
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
   // search email text for regular exp matches
	if (strEmail.search(validRegExp) == -1) 
	{
      return false;
    } 
    return true; 
}

function searchFunction(noVal){
	var searchContentID = $('#searchContentID').val();
	var searchValue = $('#searchValue').val();
	if(searchValue!=''){
		window.location.hash = '#Content/'+ searchContentID +'/1/10/0/' + searchValue;
	}else{
		alert(noVal);
	}
	return false;
}
function News(id){
	$("#mainContent").html('<div class="spinner"><img src="img/loader.gif" /></div>');
	$.post("newsMore.php", { id: id },function(data){
		$('#mainContent').html(data);
	});
	return false;
}
function Content(contentID,page,perPage,date,sVal){
	$("#mainContent").html('<div class="spinner"><img src="img/loader.gif" /></div>');
	$.post("news.php", { contentID: contentID, page: page, perPage: perPage, date: date, sVal: sVal },function(data){
		$('#mainContent').html(data);
	});
	return false;
}

function contactUs(alertText){
	email = $("#email").val();
	comment = $("#comment").val();
	if(email!="" && comment!=""){
		$("#contactUsResult").html('<img src="img/loader.gif" width="16" height="16" />');
		$.post("exe.php",{ email: email, comment: comment, action: "contactUs" }, function(data){
			$("#contactUsResult").html(data);
			$("#loader").hide();
		});
	}else{
		alert(alertText);
	}
}

// *************** HASHCHANGE START *************** 
$(function(){	
	// Bind an event to window.onhashchange that, when the hash changes, gets the
	// hash and adds the class "selected" to any matching nav link.
	$(window).hashchange( function(){
		var hash = location.hash;
		
		var urlStr = ( hash.replace( /^#/, '' ) || 'Home' );
		//var urlStr = hash.replace( /^#/, '' );
		var temp = new Array();
		temp = urlStr.split('/');
				
		eval( temp[0] )( temp[1], temp[2], temp[3], temp[4], temp[5] );

	})
	// Since the event is only triggered when the hash changes, we need to trigger
	// the event now, to handle the hash the page may have loaded with.
	$(window).hashchange();
});
// *************** HASHCHANGE END *************** 
