var menuIconWidth = 20;
var topMargin = null;
var openImage = '<img src="right.png" alt="open" />';
var closeImage = '<img src="left.png" alt="close" />';
// floating div id
var floatingDiv = "#floating";
// accordion menu div id
var accordionDiv = "#accordion";

$(document).ready(function () {
	//$("#closeOpen").html(openImage);
	topMargin = parseInt($(floatingDiv).css("top").substring(0,$(floatingDiv).css("top").indexOf("px"))) 
	$(floatingDiv).css({left: menuIconWidth - $(floatingDiv).width()});
	// for floating menu 
	$(floatingDiv).mouseenter(function () {
// show menu
$(this).stop().animate({left:  0}, "slow");
//$("#closeOpen").html(closeImage);
	}).mouseleave (function () {
// hide menu
$t = $(this);
setTimeout ( function() {
	$t.stop().animate({left: menuIconWidth - $t.width()}, "slow");
}, 4000);

//$("#closeOpen").html(openImage);
	});
	// handle the scroll event of the window.
	$(window).scroll(function () { 
// calculate the offset of the page scroll and animate the div for the floating effect.
	 	var offset = topMargin + $(document).scrollTop() + "px";
	 	$(floatingDiv).animate({top:offset}, {duration:500, queue:false});
	});
	 
	// for According Menu
	$(accordionDiv + ' > li a').click(function() {
if($(this).parent().hasClass('current')) {
	$(this).siblings('ul').slideUp(300,function() {
$(this).parent().removeClass('current');
$.scrollTo(accordionDiv,300);
	});
} else {
	$(accordionDiv + ' li.current ul').slideUp(300, function() {
$(this).parent().removeClass('current');
	});
	$(this).siblings('ul').slideToggle(300, function() {
$(this).parent().toggleClass('current');
	});
	$.scrollTo(accordionDiv, 300);
}
return false;
	});
	
});
