$(document).ready(function(){
	
	if (should_disable_splash()) {
		disable_splash();
	}
	
//	Splash message on the homepage
	if ($('#inspiration #splash').length > 0) {
		$('#inspiration #splash .outer').css({ opacity: 0.75 });
		$('#inspiration #splash .close').click(function() { $(this).parent().remove(); return false; });
	}

// If we can print show print !
	if(window.print && $('#nav-sub li #nav-meta #print').length > 0) {
		$('#nav-sub li #nav-meta #print').show();
		$('#nav-sub li #nav-meta #print').click( function() { 
			window.print();
			return false;
		});
	}
	
// Make home text banneres fully clickable
	if ($('#home-col-a .home-user-content').length > 0) {
		$('#home-col-a .home-user-content').click(function() {
			window.location = $('a[href!=]', this).attr('href');
		 });
	}
	
//if we have the send to a friend button show it an add some popups

	if($('#staf').length > 0) { 
		$('#staf').show();
		$('#staf a').nvsMediaPopup({
			popUpBackground: '#eaeaea',
			popUpsize: 'scale'
		}); 
	}

	// Enable the filter for the collection pages
	$('#men, #women, #kids, #all').click( function() {
		$('#frm_item-filter').submit();
	});
	
	// Show all products
	$('.showall').click( function() {
		$('#show_all').val(1 - $('#show_all').val());
		$('#frm_item-filter').submit();
		return false;
	});
	
//Add the popup code to a hidden anchor !!
	if($('#flashbladertoolbtn').length > 0) {
		$('#flashbladertoolbtn').nvsMediaPopup({
			popUpBackground: 'none',
			popUpsize: 'scale'
		}); 
	}
	
	if($('#flashvideoplayerbtn').length > 0) {
		$('#flashvideoplayerbtn').nvsMediaPopup({
			popUpBackground: 'none',
			popUpsize: 'scale'
		}); 
	}
		
	if ($('#frm_item-filter').length > 0) $('#frm_item-filter input[type=submit]').hide();
	
// this is to show how it works can be removed when flash is placed !!!!! 
	$('#inspiration-vsl').click(function() { flashbladertool(); });
	
// Clean form GET without x & y params in the  url.
	$('form[method=get] input[type=image]').click(function() {
		this.form.submit();
		return false;
	});
	
// Clear input fields on focus
	$("input[value!=][type=text]").focus(function () { 
		if(!$(this).attr("startvalue")) {
			$(this).attr("startvalue", $(this).val());
		} 
		if($(this).val() == $(this).attr("startvalue")) {
			$(this).val('');	
		}
	}).blur(function () { 
		if($(this).val() == '') {
			$(this).val($(this).attr("startvalue"));
		}
	});

// Inspiration slide functionality and button
	
	$('#inspiration-btn').click( function() {
	
		$('#inspiration #splash').remove();
										  
		if(ie('6.0')) { $('#inspiration-btn').hide();  }
		if($(this).hasClass("up")) {
			$('#flash-inspiration').animate( { height: 0 }, 1250, "easeInOutQuint", function() { 
				$('#inspiration-btn').removeClass("up"); 
				if(ie6('6.0')) { $('#inspiration-btn').show();  }
			});
			track_flash_event('Hide', '');
		} else {
			$('#flash-inspiration').animate( { height: '472px' }, 1250, "easeInOutQuint", function() { 
				$('#inspiration-btn').addClass("up");
				if(ie('6.0')) { $('#inspiration-btn').show();  }
			});	
			track_flash_event('Show', '');
		}
		return false;	 
	});
	
	/*
	$('#inspiration-btn').click(function() {
		$('#inspiration .nav').hide();
		if(ie('6.0')) { $('#inspiration-btn').hide();  }
		if($(this).hasClass("up")) {
			$('.carrousel, .wrapper', '#inspiration').animate( { height: 0 }, 1250, "easeInOutQuint", function() {
				$('#inspiration-btn').removeClass("up");
				if(ie6('6.0')) { $('#inspiration-btn').show(); }
			});
		} else {
			$('.carrousel, .wrapper', '#inspiration').animate( { height: '472px' }, 1250, "easeInOutQuint", function() {
				$('#inspiration-btn').addClass("up");
				if(ie('6.0')) { $('#inspiration-btn').show(); }
				$('#inspiration .nav').show();
			});	
		}
		return false;	 
	});
	*/

// Carousel functionality
	if($(".carousel").length > 0 ) {
		$(".carousel").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			visible: 4
		});
	}
	
	if($("#inspiration .carrousel").length > 0 ) {
		$("#inspiration .carrousel").jCarouselLite({
			visible: 1,
			btnGo: ['#inspiration .nav .one', '#inspiration .nav .two']
		});
	}


});

function track_flash_event(event_type, event_name) {
	pageTracker._trackEvent('Inspiratie', event_type, event_name);
}

// Quick jQuery IE 6 check
function ie6() {
	if ($.browser.msie && $.browser.version == '6.0') {
		return true;
	} else {
		return false;
	}
}

function ie(version) {
	if ($.browser.msie && $.browser.version == version) {
		return true;
	} else {
		return false;
	}
}


function init_staf() {
	$("#staf-popup form input.submit").click(function() {
		data = $("#staf-popup form").serialize();
		$("#staf-popup").html('');
		$("#staf-popup").load('/ajax/staf.php', data, function() { init_staf(); })
		return false;
	})	
}

// call this function from the FLASH !!!
function flashbladertool() {
	$('#flashbladertoolbtn').trigger('click');
}

function toon_video() {
	$('#flashvideoplayerbtn').trigger('click');
}

function should_disable_splash() {
	if (top.location != self.location) {
		return true;
	}
	
	return false;
}

function disable_splash() {
	$("#inspiration").text("");
}
