$(function() {



	/* header */

	$('#loginpassinput').focus(function() {

		$('#loginpassinput').hide();

		$('#loginpass').show();

		$('#loginpass').focus();

	});

	$('#loginuser').focus(function() {

		if ($(this).val() == 'Username') $(this).val('');

	});

	$('#topsearch').focus(function() {

		if ($(this).val() == 'Search') $(this).val('');

	});



	/* loginbox */

	$('#boxloginpassinput').focus(function() {

		$('#boxloginpassinput').hide();

		$('#boxloginpass').show();

		$('#boxloginpass').focus();

	});

	$('#boxloginuser').focus(function() {

		if ($(this).val() == 'Username') $(this).val('');

	});



	/* home slidertab */

	$('.slidertab').click(function() {

		$('.slidertab').each(function() { $(this).removeClass('currenttab'); });

		$(this).addClass('currenttab');

		$('.tabpic').each(function() { $(this).hide(); });

		$('.tabcontent').each(function() { $(this).hide(); });

		$('#tabpic'+$(this).attr('id').substr(9)).fadeIn('fast');

		$('#tabcontent'+$(this).attr('id').substr(9)).fadeIn('fast');

	});

	

	/* sidemenu */

	$('.subplus').click(

		function() {

			var id = $(this).attr('id').substr(6);

			if (! $(this).parent('div').hasClass('hasopensub')) {

				$('.hassub').each(function() {

					$(this).removeClass('hasopensub');

					$(this).find('img').attr('src', 'themes/hqip/images/plus.gif');

				});

				$(this).parent('div').addClass('hasopensub');

				$(this).children('img').attr('src', 'themes/hqip/images/minus.gif');

	

				$('.submenu:not(#submenu'+id+')').slideUp('fast');

				$('#submenu'+id).slideDown('fast');

			} else {

				$(this).parent('div').removeClass('hasopensub');

				$(this).children('img').attr('src', 'themes/hqip/images/plus.gif');

				$('#submenu'+id).slideUp('fast');

			}

		}

	);



	$('.subplus_').click(

		function() {

			var id = $(this).attr('id').substr(7);

			if (! $(this).parent('div').hasClass('hasopensub_')) {

				$('.hassub_').each(function() {

					$(this).removeClass('hasopensub_');

					$(this).find('img').attr('src', 'themes/hqip/images/plus.gif');

				});

				$(this).parent('div').addClass('hasopensub_');

				$(this).children('img').attr('src', 'themes/hqip/images/minus.gif');

				$('.submenu_:not(#submenu_'+id+')').slideUp('fast');

				$('#submenu_'+id).slideDown('fast');

			} else {

				$(this).parent('div').removeClass('hasopensub_');

				$(this).children('img').attr('src', 'themes/hqip/images/plus.gif');

				$('#submenu_'+id).slideUp('fast');

			}

		}

	);

	

	

	/* navigation */

	$('.mainmenuitem').hover(

		function() {

			if (! dropdownon) {

				dropdownon = true;

				$('.mainsubmenu').hide();

				var id = $(this).attr('id').substr(8);

				if ($('#mainsubmenu'+id).children().size() > 0) {

					$('#mainsubmenu'+id).show();

					var p = $(this).position();

					var left = p.left;

					/*var ddw = totalWidth('dropdown');

					var beg = Math.round(($(document).width() - $('#wrapper').width()) / 2);

					if ((left + $('dropdown').width()) > $('#wrapper').width()) {

						//fixme, depends of the windows size

						left = beg + ($('#wrapper').width() - ddw);

					}*/

					$('#dropdown').css('left', left);

					//$(this).css('border-color', '#fff');

					$('#dropdown').show();

				} else {

					dropdownon = false;

					dropdownoff();

				}

			}

		},

		function() {

			dropdownon = false;

			//alert($(this).html());

			if ($(this).hasClass('current'))

				$(this).css('border-color', '#deb308');

			setTimeout('dropdownoff()', 10);

		}

	);

	$('#dropdown').hover(

		function() { dropdownon = true; },

		function() { dropdownon = false; setTimeout('dropdownoff()', 10); }

	);



});



/* navigation*/

var dropdownon = false;

function dropdownoff() {

	if (! dropdownon) {

		$('#dropdown').hide();

	}

}



function totalWidth(theDiv) {

	var theDiv = $('#'+theDiv);

	var totalWidth = theDiv.width();

	totalWidth += parseInt(theDiv.css("padding-left"), 10) + parseInt(theDiv.css("padding-right"), 10);

	totalWidth += parseInt(theDiv.css("margin-left"), 10) + parseInt(theDiv.css("margin-right"), 10);

	totalWidth += parseInt(theDiv.css("borderLeftWidth"), 10) + parseInt(theDiv.css("borderRightWidth"), 10);

	return totalWidth;

}






