$(function() {
	
	$('ul.navigation_showLevel1_3 li div').hide();
	
	$("ul.navigation_showLevel1_3 li.services div ul:first-child > li:nth-child(3n+1)").addClass('clear');
	
	$("ul.navigation_showLevel1_3 li.sub").hoverIntent({
		interval: 200, // milliseconds delay before onMouseOver
		over: function(){
			var top = $(".keyvis").height() + $("ul.navigation_showLevel1_3").height() - $(this).find('div').height();
			$(this).find('div').css('top', top).show("slide", { direction: "down" }, 500);
			
		}, 
		timeout: 200, // milliseconds delay before onMouseOut
		out: function(){
			$(this).find('div').hide("slide", { direction: "down" }, 500);
		}
	});
	
	$("ul.navigation_showLevel1_3 li.services").hoverIntent({
		interval: 200, // milliseconds delay before onMouseOver
		over: function(){
			var total = $("ul.navigation_showLevel1_3").width() - Math.round($(this).position().left);
			$(this).find('div').width(total).fadeIn(500);
		}, 
		timeout: 200, // milliseconds delay before onMouseOut
		out: function(){
			$(this).find('div').fadeOut(500);
		}
	});
	
	$('ul.navigation_showLevel1_3 li div ul ul').hide();
	$("ul.navigation_showLevel1_3 li.services ul li").hoverIntent({
		interval: 0, // milliseconds delay before onMouseOver
		over: function(){
			$(this).find('ul').fadeIn(500);
		}, 
		timeout: 500, // milliseconds delay before onMouseOut
		out: function(){
			$(this).find('ul').fadeOut(500).hide();
		}
	});
	
	if ($('#happjo').length) {
		
			var flashvars = {};
			var params = {
				wmode: "transparent"
			};
			var attributes = {};

			swfobject.embedSWF("../media/happjo.swf", "flash", "510", "397", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	}
	
	if ($('div.keyvis').length) {
		blurSlide.init('div.keyvis');
	}
});

var blurSlide = {
	pos: -1,
	totalCount: 1,
	liHeight: 0,
	div: null,
	init: function(div) {
		var that = this;
		this.div = div;
		this.totalCount = $(this.div).find('li').size();
		this.liHeight = $(this.div).find('li').height();
		$(this.div).find('ul').css('margin-top', this.randomPos() + 'px');
		if (this.totalCount > 1)
			this.slide();
	},
	randomPos: function() {
		var tempPos;
		
		do {
			tempPos = -((Math.floor(Math.random()*this.totalCount)) * this.liHeight);
		} while (this.pos == tempPos)

		this.pos = tempPos;
		return this.pos;
	},
	slide: function() {
		var that = this;
		setTimeout(function() {
			$(that.div).find('span').css('background-position', 'left -' + that.liHeight + 'px');
			$(that.div).find('ul').css('margin-top', that.randomPos() + 'px');
			setTimeout(function() {
					$(that.div).find('span').css('background-position', 'bottom left');
			}, 150);
			setTimeout(function() {
					$(that.div).find('span').css('background-position', 'left top');
					that.slide();
			}, 250);
		}, 5000);
	}
}

//.randomPos()
