// JavaScript Document

var matimer=null;

$(document).ready(function()
{
	var tmpobjarr;
	
	if ((tmpobjarr = $("div.navbox")).length > 0) {
		$(tmpobjarr).each(function() {
			$(this).bind('mouseover',function() {
				//$(this).stop();
				//$(this).animate({backgroundPosition:'0px 0px'});
				$(this).css({backgroundPosition:'0px 0px'});
			});
			$(this).bind('mouseout',function() {
				//$(this).stop();
				//$(this).animate({backgroundPosition:'-200px 0px'});
				$(this).css({backgroundPosition:'-200px 0px'});
			});
		});
	}
	
	if ((tmpobjarr = $("div.fgnavimg")).length > 0) {
		$(tmpobjarr).each(function() {
			$(this).css({visibility:"visible",opacity:0});
		});
	}
	if ((tmpobjarr = $("div.navbox div.nbmenu ul li")).length > 0) {
		$(tmpobjarr).each(function() {
			$(this).bind('mouseover',function() {
				$(this).stop();
				$(this).animate({'background-color':'#666666'});
				$(this).children("a").stop();
				$(this).children("a").animate({'color':'#ffffff'});
				$(this).find("span").addClass("active");
			});
			$(this).bind('mouseout',function() {
				$(this).stop();
				$(this).animate({'background-color':'#f7f7f7'});
				$(this).children("a").stop();
				$(this).children("a").animate({'color':'#444444'});
				$(this).find("span").removeClass("active");
			});
		});
	}
	
	if ((tmpobjarr = $("ul.sidenav li")).length > 0) {
		$(tmpobjarr).each(function() {
								   
			$(this).children("a").css({"text-decoration":"none"});
			//$(this).css({padding:"2px 5px 2px 0"});
			$(this).bind('mouseover',function() {		  
				$(this).stop();
				//$(this).animate({'background-color':'#666666'});
				$(this).css({'background-color':'#666666'});
				$(this).children("a").stop();
				$(this).children("a").animate({'color':'#ffffff'});
				$(this).find("span").addClass("active");
			});
			$(this).bind('mouseout',function() {
				$(this).stop();
				//$(this).animate({'background-color':'transparent'});
				$(this).css({'background-color':'transparent'});
				$(this).children("a").stop();
				$(this).children("a").animate({'color':'#444444'});
				$(this).find("span").removeClass("active");
			});
		});
	}
	
	if ((tmpobjarr = $("div#adressparade")).length > 0) {
		$("div#adressparade div.tx-ttaddress-pi1").css({width:$("div#adressparade div.tx-ttaddress-pi1 div.vcard").length*135});
		var i=0;
		$("div#adressparade div.tx-ttaddress-pi1 div.vcard").each(function() {
				$(this).css({float:"none",position:"absolute",top:0,left:(i*135)});
				i++;
		});
		
		tmpobjarr.bind("mousemove",function(e) {
				var percent =(e.pageX-this.offsetLeft)/$(this).width();
				if (percent < 0.40) {
						mhz_passer.maspeed = 100*(0.40-percent);
				} else if (percent > 0.60) {
						mhz_passer.maspeed = 100*(0.60-percent);
				} else {
					mhz_passer.maspeed = 0;
				}
		});
		tmpobjarr.bind("mouseover",function(e) {
				if (matimer != null) {
					window.clearInterval(matimer);
				}
				mhz_passer.maobj = $("div#adressparade div.tx-ttaddress-pi1");
				mhz_passer.maxpos = $("div#adressparade div.tx-ttaddress-pi1").position().left;
				mhz_passer.maxposmin=$("div#adressparade").width()-($("div#adressparade div.tx-ttaddress-pi1 div.vcard").length*135);
				matimer = window.setInterval("mhz_passer.mamove()", 32);
		});		
		tmpobjarr.bind("mouseout",function() {
				if (matimer != null) {
					window.clearInterval(matimer);
				}
		});		
	}
	
	
	
});

var mhz_passer = new function() {
	
	this.maspeed=0;
	this.maxpos=0;
	this.maxposmin = 0;
	this.maobj = null;
	this.fgnav = function(fgnavid) {
		
		$("div.fgnavimg").each(function() {
			$(this).stop();
			$(this).animate({opacity:0});
		});
		if (fgnavid != undefined) {
			$("div#"+fgnavid).stop();
			$("div#"+fgnavid).animate({opacity:1});
			$("div#imgloop").stop();
			$("div#imgloop").animate({opacity:0});
		} else {
			$("div#imgloop").stop();
			$("div#imgloop").animate({opacity:1});	
		}
	}
	
	this.mamove = function() {
		mhz_passer.maxpos += mhz_passer.maspeed;
		if (mhz_passer.maxpos>0) {
			mhz_passer.maxpos = 0;
		} else if (mhz_passer.maxpos < mhz_passer.maxposmin) {
			mhz_passer.maxpos = mhz_passer.maxposmin;
		}
		mhz_passer.maobj.css({left:Math.round(mhz_passer.maxpos)});
		//$("div#adressparade div.tx-ttaddress-pi1").css({left:Math.round(mhz_passer.maxpos)});
	}
	
}
