	//start google analytics tracking
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-20434304-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();


$(document).ready(function () {
	//Check if url hash value exists (for bookmark)
	//$.history.init(pageload);	
	initializeMenu();
	//highlight the selected link
	$('a[href=' + document.location + ']').addClass('selected');

	var hashpart = document.location.hash;
	hashpart = hashpart.replace(/^.*#/, '');
	//for back button
 	//$.history.load(hashpart);	

	var page = $.getUrlVar("p");
	if (page != null) {
	 	$("div.section").hide();
		$("div#"+page).fadeIn("slow");
	 	$('.menuitem').each(function(){
	 		var url = document.location.href;
	 		var ahref = $(this).find("a").attr("href");
	 		if (url.indexOf(ahref) > -1) {
	 			$(this).addClass('selected');
	 		}
	 	});
	}

 	//Search 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
	 	//$('.menuitem>a').removeClass('selected');
	 	
	 	//hide the content and show the progress bar
	 	$('#content').hide();
	 	$('#loading').show();
	 	
	 	//run the ajax
		getPage();
	
		//cancel the anchor tag behaviour
		return false;
	});	
	
	//handle highlighting
	var pub = $.getUrlVar("hl");
	if (pub != null) {
		$("div#"+pub).addClass("hi");
		$('html, body').animate({
		    scrollTop: $("div#"+pub).offset().top
		}, 2000);	
	}
});
	

function pageload(hash) {
	//if hash value exists, run the ajax
	if (hash) getPage();    
}
		
function getPage() {
	
	//generate the parameter for the php script
	var data = 'page=' + document.location.hash.replace(/^.*#/, '');
	$.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 menuItem(mi, txt){
	return '<a href="#'+mi+'">'+txt+'</a>';
}

function initializeMenu() {
	var menu = $("#menu");
	var newMenu = '<ul id="jmenu"><li><a href="index.html">Home</a></li>';

	newMenu += '<li><a href="about.html?p=who">About</a><ul>';
	newMenu += '<li><a href="about.html?p=who">Who Are We?</a></li>';
	newMenu += '<li><a href="about.html?p=history">History</a></li>';
	newMenu += '<li><a href="about.html?p=board">Board &amp; Management</a></li>';
	newMenu += '<li><a href="about.html?p=facilities">Facilities</a></li>';
	newMenu += '</ul></li>';

	newMenu += '<li><a href="technology.html?p=why">Technology</a><ul>';
	newMenu += '<li><a href="technology.html?p=why">Why Ceramics?</a></li>';
	newMenu += '<li><a href="technology.html?p=features">Key Features &amp; Benefits</a></li>';
	newMenu += '<li><a href="technology.html?p=how">How the Technology Works</a></li>';
	newMenu += '<li><a href="technology.html?p=ip">Intellectual Property</a></li>';
	newMenu += '</ul></li>';

	newMenu += '<li><a href="healthcare.html?p=therapeutic">Healthcare</a><ul>';
	newMenu += '<li><a href="healthcare.html?p=therapeutic">Delivery of Therapeutic Molecules</a></li>';
	newMenu += '<li><a href="healthcare.html?p=biodegradable">Biodegradability</a></li>';
	newMenu += '<li><a href="healthcare.html?p=sirna">Delivery of siRNA</a></li>';
	newMenu += '<li><a href="healthcare.html?p=oral">Oral Delivery of Peptides &amp; Proteins</a></li>';
	newMenu += '<li><a href="healthcare.html?p=partners">Healthcare Partnerships</a></li>';
	newMenu += '</ul></li>';

	newMenu += '<li><a href="industrial.html?p=smart">Industrial</a><ul>';
	newMenu += '<li><a href="industrial.html?p=smart">&quot;Smart&quot; Coatings</a></li>';
	newMenu += '<li><a href="industrial.html?p=corrosion">Anti-Corrosion Coatings</a></li>';
	newMenu += '<li><a href="industrial.html?p=cosmetics">Cosmetics &amp; Cosmeceuticals</a></li>';
	newMenu += '<li><a href="industrial.html?p=food">Food &amp; Nutriceuticals</a></li>';
	newMenu += '<li><a href="industrial.html?p=partners">Industrial Partnerships</a></li>';
	newMenu += '</ul></li>';

	newMenu += '<li><a href="news.html">News & Events</a></li>';

	newMenu += '<li><a href="publications.html">Publications</a></li>';

	newMenu += '<li><a href="contact.html">Contact Us</a></li>';

	newMenu += '</ul>';
	menu.replaceWith(newMenu);
	$('#jmenu').jmenu({animation:'fade',duration:500});
}



/*
jQuery menu

Example:
$(document).ready(function()
{
    $('#jmenu').jmenu({animation:'fade',duration:100});
});

(c) 2010 Sawanna Team (http://sawanna.org)
*/

var jmenu={
    effect: 'fade',           /* default animation effect */
    duration: 400,         /* default duration */
    set: function (settings)
    {
       try
        {
            if (settings.animation == 'show') { this.effect='show'; }
            if (settings.animation == 'slide') { this.effect='slide'; }
            if (settings.animation == 'fade') { this.effect='fade'; }
        } catch (e) {}
        
        try
        {
            this.duration=settings.duration;
        } catch (e) {} 
    },
    fix_pos:function(elem)
    {
        if ($(elem).parent('ul').parent('li').length)
        {
            $(elem).children('ul').eq(0).css({marginTop:-$(elem).height(),marginLeft:$(elem).width()});
        } else
        {
            $(elem).children('ul').eq(0).css({'top':$(elem).offset().top+$(elem).height(),'left':$(elem).offset().left});
        }
    },
    show:function(elem)
    {
        if (this.effect=='fade') { $(elem).children('ul').eq(0).stop(1,1).fadeIn(this.duration); }
        else if (this.effect=='slide') {$(elem).children('ul').eq(0).stop(1,1).slideDown(this.duration); }
        else if (this.effect=='show') { $(elem).children('ul').eq(0).stop(1,1).show(this.duration); }
    },
    hide: function(elem)
    {
        $(elem).children('ul').eq(0).stop(1,1).fadeOut(100);
    }
}

jQuery.fn.jmenu=function(settings)
{
    jmenu.set(settings);
    
    $(this).find('li').each(function()
    {
            $(this).hover(
                function()
                {
                    //jmenu.fix_pos(this);
                    jmenu.show(this);
                },
                function()
                {
                    jmenu.hide(this);
                }
            );
    });
}

//Thanks: http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
$.extend({
	  getUrlVars: function(){
	    var vars = [], hash;
	    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	    for(var i = 0; i < hashes.length; i++)
	    {
	      hash = hashes[i].split('=');
	      vars.push(hash[0]);
	      vars[hash[0]] = hash[1];
	    }
	    return vars;
	  },
	  getUrlVar: function(name){
	    return $.getUrlVars()[name];
	  }
	});

function showsyn(e) {
	return;
	$('.synopsis',e.parentNode).slideDown();
}
function hidesyn(e) {
	return;
	$('.synopsis',e.parentNode).slideUp();
}
function closePopup(p) {
    $('#popupshade').css('display', 'none');
    $('#'+p).css('display', 'none');
}
function showPopup(p) {
    //$('#popupshade').fadeIn();
    $('#'+p).fadeIn(800);
}

