$(function (){
	
	//EQ
	var mHeight = $('#main').height();
	var sHeight = $('#side .content').height();
	if (mHeight > sHeight) {
		$('#side .content').css('min-height' , mHeight - 33);
	}
	
	// LAYOUT
	$('#mainMenu a.active').parent().next().addClass('next2Active');
	$('#categoryMenu > ul:last').addClass('last');
	$('.corners').append('<div class="tl"/><div class="tr"/><div class="bl"/><div class="br"/>');
	
	// FORMS - focus and blur
	$('.input input.textfield, .input textarea').focus(function () {
		$(this).select().parent().addClass('focus');
	});
	$('.input input.textfield, .input textarea').blur(function () {
		$(this).parent().removeClass('focus');
	});
	// FORMS - clicking on hint
	$('.input div.hint').click(function() {
		$(this).parent().addClass('focus').find('input').select();
	});
	// FORMS - Empty filled fields on blur
	$('.input input.textfield, .input textarea').each(function () {
		if ($(this).val() != "") {
			$(this).parent().addClass('filled');
		} else {
			$(this).parent().removeClass('filled');
		};
		$(this).blur(function() {
			$(this).parent().removeClass('focus');
			if ($(this).val() != "") {
				$(this).parent().addClass('filled');
			} else {
				$(this).parent().removeClass('filled');
			};
		});
	});
	
	// CUSTOM SELECT
	// Show on click
	$(".customSelect div.selected a").click(function() {
		$(this).parents('.customSelect').addClass("customSelectDown").css({ position: "relative", zIndex: "3" }).parents(".selector").css({ position: "relative", zIndex: "1" }); return false;
	});
	// Hide on mouseout
	$(".customSelect").mouseleave(function() {
		$(this).removeClass("customSelectDown").css({ position: "static", zIndex: "0" }).parents(".selector").css({ position: "static", zIndex: "0" });;
	});
	// Hide on click
	$(".customSelect ul a").click(function() {
		var $option = $(this).html();
		$(this).parents(".customSelect").removeClass("customSelectDown").css({ position: "static", zIndex: "0" }).find("div.selected a").html($option); return true;
	});
	// Set width from parent to child
	$(".customSelect").each(function(i) {
		var $customSelectWidth = $(this).width();
		$(this).find(".dropdown").width($customSelectWidth);
	});
	
	// STICKYBAR
	$('#stickybar li.item').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	$('#stickybar a.level1').click(function() {
		pageMask();
		$('#pageMask').show();
		$('#stickybar li.item').css('zIndex', '1').find('.dropdown:visible').slideUp();
		$(this).parent('li.item').css('zIndex', '2').find('.dropdown').slideDown();
		return false;
	});
	$('#stickybar a.close, #pageMask').click(function() {
		$('#pageMask').hide();
		$('#stickybar li.item').css('zIndex', '1').find('.dropdown:visible').slideUp();
		return false;
	});
	
	// Fully clickable link
	$('#headerContact .col-02, #headerContact .col-03').click(function(event) {
		if ($(event.target).is(":not('a, input, label')") ) {
			window.location = $(this).find('a').attr("href");
	}
});

	
});

// Resize pageMask to html-size
function pageMask() {
	var htmlHeight = $(document).height();
	/*
	if ($.browser.msie && $.browser.version == 6.0) {
		var htmlHeight = $('#wrapper').height(); // Different height calculation for IE6
	}
	*/
	$('#pageMask').height(htmlHeight);
}
