$(function (){
	
	// MENU HOVER
	$('#mainMenu li').hover(function() {
	    $(this).addClass("hover");
		Cufon.refresh('#mainMenu a.level1');
	}, function() {
	    $(this).removeClass("hover");
		Cufon.refresh('#mainMenu a.level1');
	});
	$('#mainMenu li:has(ul)').hover(function() {
	    $(this).addClass("parentHover");
	}, function() {
	    $(this).removeClass("parentHover");
	});
	$("#mainMenu ul ul").each(function(i) {
		var $dropdownWidth = $(this).parent().width();
		if ( $(this).width() < $dropdownWidth ) $(this).width($dropdownWidth);
	});
	
	// Initialize the tab navigation
    var tabContainers = $('#tabContainer > div.tabContent');
    tabContainers.hide().filter(':first').show();
    $('#tabNavigation a').click(function () {
        tabContainers.hide();
        tabContainers.filter(this.hash).show();
        $('#tabNavigation li').removeClass('active');
        $(this).parent('li').addClass('active');
		Cufon.replace('#tabNavigation a');
		return false;
    }).filter(':first').click();
	// Activate tab omschrijving
	$('#productDetails a.extend').click(function () {
		tabContainers.hide();
		$('#omschrijving').show();
        $('#tabNavigation li').removeClass('active');
        $('#tabNavigation li:nth(1)').addClass('active');
		Cufon.replace('#tabNavigation a');
	});
	
	// EQUALHEIGHTS (1/2)
	$(".block_4categoryEntries .item").equalHeights();
	$(".block_popular .item").equalHeights();
	$(".recommended_duoColumn .row .item").equalHeights();
	$(".duoFrame .frame").equalHeights();
	$("#productSliderArea ul").equalHeights();
	
	$(".filterContentFrame .frame").equalHeights();
	setTimeout("$('.filterContentFrame .frame').equalHeights();", 50);
	$(".serviceEntryRow .serviceEntry").equalHeights();

	var frameHeight = $('.filterFrame').height();
//	$('.fullFrameSmall').height(frameHeight-70); 
	$('.fullFrameSmall').css('min-height', frameHeight-70); 
	
	
	// LOGIN FIELDS
	$("#iframe_login .input input, #loginBox .input input").each(function() {
		if ($(this).val() == 0) {
			$(this).parent(".input").css({ backgroundPosition: "left top" });
		} else {
			$(this).parent(".input").css({ backgroundPosition: "left bottom" });
		};
	});
	$("#iframe_login .input input, #loginBox .input input").focus(function() {
		$(this).parent(".input").css({ backgroundPosition: "left bottom" });
	});
	$("#iframe_login .input input, #loginBox .input input").blur(function() {
		if ($(this).val() == 0) {
			$(this).parent(".input").css({ backgroundPosition: "left top" });
		} else {
			$(this).parent(".input").css({ backgroundPosition: "left bottom" });
		};
	});
	
	// LIST PACKAGE styling
//	$('table.list_package tr').not('.head, .spacer, .total, .highlight').filter(':odd').addClass('odd');
	$('table.list_package').find('tr.head:first').addClass('first');
	
	
	// ROLLOVER IMAGES (1/2)
	IMAGE.rollover.init();
	
});


// ROLLOVER IMAGES (2/2)
IMAGE = {};
IMAGE.rollover = {
   init: function(selectorParent) {
	  var selector = ".rollover";
	  if (selectorParent) {
		  selector = selectorParent + " " + selector;
	  }
      this.preload(selector);
      IMAGE.rollover.applyRolloverEffect(selector);
   },
   applyRolloverEffect: function(selector) {
      $(selector).hover(
         function () { $(this).attr( 'src', IMAGE.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', IMAGE.rollover.oldimage($(this).attr('src')) ); }
      );
   },
   preload: function(selector) {
      $(window).bind('load', function() {
         $(selector).each( function( key, elm ) { $('<img>').attr( 'src', IMAGE.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   newimage: function( src ) {
      return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_on' + src.match(/(\.[a-z]+)/)[0];
   },
   oldimage: function( src ) {
      return src.replace(/_on/, '');
   }
};

// EQUALHEIGHTS (2/2)
$.fn.equalHeights = function(minHeight, maxHeight) {
	tallest = (minHeight) ? minHeight : 0;
	this.each(function() {
		if($(this).height() > tallest) {
			tallest = $(this).height();
		}
	});
	if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
	return this.each(function() {
		if ($.browser.msie && $.browser.version == 6.0) { 
			$(this).height(tallest); 
		}
		$(this).css("min-height", tallest + "px");
	});
}
