// This script requires the use of the jQuery Cookie plugin available at http://plugins.jquery.com/files/jquery.cookie.js.txt
jQuery(document).ready(function(){
	if (jQuery.cookie('selamatDatang')) {
		jQuery("#message").css("display:","none");
    } else {
		jQuery('#message').delay(3000).slideDown(200);
		}
		
		
	/* added by Ross 02-Aug-2010 */
	if(jQuery("#aboutMenu").length) {
		scrollFeatSidebar();
		jQuery(window).scroll(function() {
			scrollFeatSidebar();
		});
	}

});

// To hide the message but show it again on page reload
function hideMessage(){
jQuery('#message').delay().slideUp(200);
}

// To hide the hide the message and set the cookie so when the page is reloaded the message does not appear
function hideForever(){
jQuery('#message').delay().slideUp(200);
jQuery.cookie('selamatDatang', 'foo', { expires: 7 });
}

// Optional function to show message manually on the demo page
function showMessage(){
jQuery('#message').delay().slideDown(500);
}

// Auto Hide/show Joomla! System-Message
/*jQuery(document).ready(function(){
	var sysmsg 		= document.getElementById('system-message');
	if (!sysmsg){
		jQuery("#system-message").css("display:","none");
    } else {
		jQuery('#system-message').delay(100).slideDown(200).delay(4000).slideUp(200);
	}
});*/


jQuery(document).ready(function() {
	jQuery(".account").click(function(e) {          
		e.preventDefault();
		jQuery("div#user_menu").toggle();
		jQuery(".account").toggleClass("menu-open");
	});
	
	jQuery("div#user_menu").mouseup(function() {
		return false
	});
	jQuery(document).mouseup(function(e) {
		if(jQuery(e.target).parent("a.account").length==0) {
			jQuery(".account").removeClass("menu-open");
			jQuery("div#user_menu").hide();
		}
	});			
	
});

function scrollFeatSidebar()
{
	//get the container limits
	var topScrollLimit = jQuery(".page").offset().top;
	var botScrollLimit = jQuery(".page").height() - jQuery("#aboutMenu").height() + 1000;
	var curPosition = window.pageYOffset;
	var scrollPosition = 0;

	//only scroll if the offset is within this limit
	if(curPosition > topScrollLimit && curPosition < botScrollLimit)
	{
		scrollPosition = curPosition - topScrollLimit;
	}
	else if (curPosition > botScrollLimit)
	{
		scrollPosition = jQuery(".page").height() - jQuery("#aboutMenu").height() - 1000;
	}
	else
	{
		scrollPosition = 0;
	}
	jQuery("#aboutMenu").animate({top : scrollPosition + "px"},{duration:500,queue:false});
	//console.log("Top Scroll Limit: " + topScrollLimit + ", Bottom Scroll Limit: " + botScrollLimit + ", Current Position: " + curPosition + ", scrollPosition: " + scrollPosition);
}

