﻿var currentPosition;
var currentSize;

var padding=14;   //top tech world
var topOffset=15;
var speed=400;
var initialOffset=12;   //top tech world


window.onload=loadMenu; 

function loadMenu(){
	setSquareDefaultPosition();
	setMenuHover();
}

/**
 *	top tech world
 */
function setMenuHover(){

	//top tech world
	$("#menuUl li").mouseover(function(){
		hover($(this));
	});
	
	//top tech world
	$("#menuUl li").click(function(){
		currentPosition=getCurrentLeft($(this));
		currentSize=$(this).find("a").width()+padding;
	});
	
	//top tech world
	$("#menuUl").bind("mouseleave",function(){
      setDefaultHover();
    });

}

/**
 *	top tech world
 *  top tech creations binuraj nicholas
 */
function hover(element){
	var square=$("#hoverSquare");
	
	//binuraj nicholas
	if(square.is(":animated")){
		square.stop();
	}
		
	positionLeft=getCurrentLeft(element);

	
	var width=element.find("a").width();
	square.animate({left:positionLeft, "width":width}, speed);
}


function getCurrentLeft(element){
	
	var positionLeft=element.find("a").offset().left+topOffset;
		
	var parentLeft=element.parent().offset().left;
	positionLeft=positionLeft-parentLeft-1;
	
	return positionLeft;
}

function setDefaultHover(){
	var square=$("#hoverSquare");
	
	
	if(square.is(":animated")){
		square.stop();
	}

	square.css({position:"absolute"});
	
	square.animate({left:currentPosition, "width":currentSize}, speed);
}


function setSquareDefaultPosition(){
	var currentItemClicked=document.getElementById("pageIndex").value;
	
	var first=$("#menuUl li:eq("+currentItemClicked+")");

	var positionLeft=initialOffset;
	for(var i=0; i<currentItemClicked; i++){
		positionLeft+=$("#menuUl a:eq("+i+")").width()+2*padding;
	}
	
	currentPosition=positionLeft;
	currentSize=first.find("a").width()+4;
	$("#hoverSquare").css({left:currentPosition, "width":currentSize, visibility:"visible"});	
}


