$(document).ready(function() {
	var title = $("title").html();
	body_syle_array = ["bg1", "bg2", "bg3"];
	random_style = body_syle_array[Math.floor(Math.random()*body_syle_array.length)];
	$("body").attr("class", random_style);

    $("ul.sf-menu").superfish({
    	animation: {height:'show'},   // slide-down effect without fade-in
	    delay:     100               // 1.2 second delay on mouseout
	});

    $("#newsletteremail").click(function() {
		$(this).val("");
	});

	$(".datepicker").datepicker({
			changeMonth: true,
			changeYear: true,
			altFormat: 'yy-mm-dd',
			dateFormat: 'yy-mm-dd',
			yearRange: '1900:2010'
	});

	$("#login").dialog({
		bgiframe: true,
		autoOpen: false,
		height: 250,
		width: 350,
		modal: true
	});


	/*if (window.parent.document.location.protocol == "http:")
	{
		$('.navBox a, .ajax').ezjax({
			  container: '#rightCntr',
			  effect: null,
			  title: title,
			  easing: null,
			  bind: '.ajax'
		});
	}*/
	if($('#loggedin').html() == 1)
	{
		$('.nologgin').hide();
		$('.loggedin').show();
	}
	else
	{
		$('.loggedin').hide();
		$('.nologgin').show();
	}
	var delayed;
	$("#SEARCHSTRING").click(function() {
		$(this).val("").replace(/(<([^>]+)>)/ig,"");
	});
	$("#SEARCHSTRING").keyup(function() {
		clearTimeout(delayed);
		var value = this.value.replace(/(<([^>]+)>)/ig,"");
		if (value) {
			delayed = setTimeout(function() {
				$("#rightCntr").hide();
				$("#rightCntr").before('<img id="loader" src="' + $("#siteurl").html() + 'cms/templates/images/ajax-loader.gif"/>');
				$.ajax({
					type: "POST",
					url: $("#siteurl").html() + "search/",
					data: "SEARCHSTRING="+ value,
					success: function(theResponse) {
						$("#rightCntr").html(theResponse);
						$("#loader").remove();
						$("#rightCntr").show();
					}
				});
			 }, 1000);
		}
	});
	$("#brandsubmit").hide();
	$("#brandselect").change(function () {
		option = $("option:selected", this).val();
		if(option != "")
		{
			$("#brandsubmit").show();
			$("#brandsubmit").attr("href", option);
		}
		else
		{
			$("#brandsubmit").hide();
		}
	});

	$("#rightCntr").jImagePreloader();
	$("#category34nav").scrolldiv();
	$(".cmspage").equalizeCols();
	$('.tooltip').tipsy({html: true, live: true, gravity: 's'});
});

function recentBox()
{

	$.ajax({
		type: "POST",
		url: $("#siteurl").html() + "index/clearvisited/",
		success: function(msg) {
		}
	});
	$(".recentBox").animate({height : 30}, 1000);
	return false;
}

function initMenu(menu) {
	$(menu +' ul').hide();
	$(menu +' ul:first').show();
	$(menu +' li a').click(
		function() {
			var checkElement = $(this).next();
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				return false;
	        }
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$(menu +' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
	        }
	    }
	);
}

function login()
{
	var url = $("#siteurl").html();
	if (window.parent.document.location.protocol != "http:")
	{
		url = url.replace(/http/i,"https")
	}
	$.ajax({
		type: "POST",
		url: url + "login/",
		success: function(theResponse) {
			$("#login").html(theResponse);
			$("#login").dialog('option', 'buttons', {
				"Ok": function() {
					$('#inloggen').ajaxSubmit({target: '#login'});
				}
			});
			$("#login").dialog( 'open' );
		} ,
		error: function(theResponse) {
			alert(url);
		}
	});


}
