﻿var $jq = jQuery.noConflict();

$jq(document).ready(function() { 	
	$jq('#header #login input.u').focus(function() {
		clearField('.u');
	});
	$jq('#header #login input.p').focus(function() {
		clearField('.p');
	});
	window.onload = function() {placeMenuDrops(true,true)};
});
$jq(window).load(function () {
    if ($jq('#slider').length > 0) {
        $jq('#slider').nivoSlider({
            animSpeed: 500,
            pauseTime: 5000,
            pauseOnHover: true,
            directionNav: true,
            directionNavHide: true,
            effect: 'fade',
            controlNav: false
            /*lastSlide: function () { $jq('#slider').data('nivoslider').stop(); }*/
        });
    }
});
$jq(window).resize(function() {
	placeMenuDrops(false,true);
});

function clearField(theInput) {
	//alert($jq(theInput).attr("value")+'..'+$jq(theInput).val());
	if ($jq(theInput).attr("value")==$jq(theInput).val()&&!$jq(theInput).hasClass('writing')) {
		$jq(theInput).val('');
		$jq(theInput).addClass('writing');
	}
}

function closeMenuDrops() {
	$jq('.submenu').css('display','none');
}

function showDrop(id,bool) {
	if (bool == true) {
		id.css('display','block');
	} else {
		id.css('display','none');
	}
}

function placeMenuDrops(top,left) {
	if ($jq('#menu').length>0 && $jq('#submenus').length>0) {
		$jq('#header .grid_3').mouseenter(function() {
			closeMenuDrops();
		});
		$jq('#header .grid_4').mouseenter(function() {
			closeMenuDrops();
		});
		$jq('#mainContent').mouseenter(function() {
			closeMenuDrops();
		});
		$jq('#menu ul li').each(
			function(intIndex){
				intIndex += 1;
				if ($jq('#submenu_c'+intIndex).length>0) {
					if (top == true) {
						$jq('#submenu_c'+intIndex).css( 'top', $jq('#c'+intIndex).offset().top );
					}
					if (left == true) {
						$jq('#submenu_c'+intIndex).css( 'left', $jq('#c'+intIndex).offset().left-1 );
					}
					$jq('#c'+intIndex).mouseenter(function() { //mouseover på huvudmenyn
						closeMenuDrops();
						showDrop($jq('#submenu_c'+intIndex),true);
						$jq('#submenu_c'+intIndex+' .subl').height($jq('#submenu_c'+intIndex+' .subf').height());
						$jq('#submenu_c'+intIndex+' .subr').height($jq('#submenu_c'+intIndex+' .subf').height());
					});
					$jq('#submenu_c'+intIndex).mouseleave(function() { //mouseout på undermenyn
						showDrop($jq('#submenu_c'+intIndex),false);
						$jq('#c'+intIndex+' a').removeClass('hover');
					});
					$jq('.closeSubs').mouseenter(function() { //mouseout på hela menyn
						closeMenuDrops();
					});
					$jq('#submenu_c'+intIndex).mouseenter(function() { //mouseover på undermenyn
						$jq('#c'+intIndex+' a').addClass('hover');
					});
					if (!$jq('#submenus').mouseover() && !$jq('#menu').mouseover()) {
						closeMenuDrops();
					}
				}
			}
		);
	}
}
