$(document).ready(function() {

    //alert(window.innerHeight);
    $("div#spinner").hide();
    $("#toplink").fadeIn();
    $("a.cartlink").fadeIn();

    $("#q").autocomplete('/autocomplete.php', {
                    selectFirst: false,
                    extraParams: {
                        q: function() { return $("#q").val(); }
                    }
    });

    $('#zoek').click(function() {
       if ($('#q').val())
         $('#sform').submit();
    });
    
    $('#agreecb').click(function() {
      $('#agreediv').slideUp();
      $('#regdiv').slideDown();
    });

    $('.showmore').click(function() {
       var currentId = $(this).attr('id');
       $('.ordercontainer').slideUp();
       $('.showmore').show();
       $(this).hide();
       $('.showless').hide();
       $('#less_'+ currentId).show();
       $('#order_'+ currentId).slideDown('slow');
    });
    
    $('.showless').click(function() {
       $('.ordercontainer').slideUp();
       $(this).hide();
       $('.showmore').show();
    });

    $('#cartconfirm').click(function() {
       $('#confirmform').submit();
    });

   $('#showprice').change(function() {
       $('#priceform').submit();
    });

    $("div.grouppreview").hover(
       function() {
       $(this).css('border', '1px solid #FF8C00');
       },
       function() {
       $(this).css('border', '1px solid #ccc');
    });

    $("div.tablerow").hover(
       function() {
       $(this).css('border', '1px solid #FF8000');
       $(this).find('a.arrowlink').show();
       },
       function() {
       $(this).css('border', '1px solid #ccc');
       $(this).find('a.arrowlink').hide();
    });
    
    $("div.homepage_left,div.homepage_right,").hover(
       function() {
       $(this).find('a.arrowlink').show();
       },
       function() {
       $(this).find('a.arrowlink').hide();
    });
    
	$('#showmore').click(function() {
       $('.footerrowplus').show();
       $(this).hide();
       return false;
	});

    $("div#productimage").hover(
       function() {
       $("img#magnifyimage").animate({opacity: 0.25}, 1);
       $("img#magnifyimage").show();
       },
       function() {
       $("img#magnifyimage").hide();
    });
    
    $("a#large_image").fancybox(
    {
		'hideOnContentClick': true,
		'opacity': true,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic'
	});

	$('#morelinks').click(function() {
       $('#usermenu').slideUp('normal');
       $('#shoppingcart').slideUp('normal');
       $('#moremenu').slideDown('normal');
       return false;
	});

	$('#userlinks').click(function() {
	   $('#moremenu').slideUp('normal');
       $('#shoppingcart').slideUp('normal');
       $('#usermenu').slideDown('normal');
       return false;
	});

	$('#showcart').click(function() {
       $('#moremenu').slideUp('normal');
       $('#usermenu').slideUp('normal');
       $('#shoppingcart').slideDown('normal');
       return false;
	});

	$('body').click(function() {
       $('#moremenu').slideUp('normal');
       $('#usermenu').slideUp('normal');
       $('#shoppingcart').slideUp('normal');
	});

    $('#q').focus(function() {
       $('#q').css('border-color', '#FF8C00');
	});

    $('#q').blur(function() {
       $('#q').css('border-color', '#000000');
	});

    $(function() {
       $("#q").focus();
    });
    
    $("#prodvideo").click(function() {
	   $.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'overlayShow'	: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
		    'speedIn'		: 600,
	        'speedOut'		: 200,
            'title'			: this.title,
			'width'         : 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	   return false;
    });

   	$("a[href*=cart.php]").fancybox({
        'scrolling'     :  'no',
        'titleShow'		: false,
        'autoDimensions':  false,
        'transitionIn'	:  'elastic',
		'transitionOut'	:  'elastic',
		'speedIn'		:  600,
		'speedOut'		:  200,
		'height'        :  164,
		'width'         :  450,
		'overlayShow'	:  false,
		'type'          :  'iframe',
 	    'onClosed'		: function() {
          if (parent.location.href.indexOf('page=cart')>0)
            parent.location.reload();
          else{
          $('#shoppingcart').slideDown();
          $.get("/cartamount.php", function(data) {
               $("#cartamount").html(data);

          });
          $('#shoppingcart').slideUp(1500);
          }
         }
    });
    
   	$("a[href*=favorites.php]").fancybox({
        'scrolling'     :  'no',
        'titleShow'		:  false,
        'autoDimensions':  false,
        'transitionIn'	:  'elastic',
		'transitionOut'	:  'elastic',
		'speedIn'		:  600,
		'speedOut'		:  200,
		'height'        :  160,
		'width'         :  400,
		'overlayShow'	:  false
    });


   	$("a[href*=contact.php]").fancybox({
        'scrolling'     :  'no',
        'titleShow'		:  false,
        'autoDimensions':  false,
        'transitionIn'	:  'elastic',
		'transitionOut'	:  'elastic',
		'speedIn'		:  600,
		'speedOut'		:  200,
		'height'        :  450,
		'width'         :  640,
		'overlayShow'	:  false,
		'type'          :  'iframe'
    });
    
   	$("a[href*=register.php]").fancybox({
        'scrolling'     :  'no',
        'titleShow'		: false,
        'autoDimensions':  false,
        'transitionIn'	:  'elastic',
		'transitionOut'	:  'elastic',
		'speedIn'		:  600,
		'speedOut'		:  200,
		'height'        :  520,
		'width'         :  640,
		'overlayShow'	:  false,
		'type'          :  'iframe',
		'onClosed': function() {
                    parent.location.reload(true);
                    }
    });

   	$("a[href*=login.php]").fancybox({
        'scrolling'     :  'no',
        'autoDimensions':  false,
        'transitionIn'	:  'elastic',
		'transitionOut'	:  'elastic',
		'speedIn'		:  600,
		'speedOut'		:  200,
		'height'        :  140,
		'width'         :  240,
		'overlayShow'	:  false,
		'type'          :  'iframe'
    });

   	$("a[href*=password.php]").fancybox({
        'scrolling'     :  'no',
        'autoDimensions':  false,
        'transitionIn'	:  'elastic',
		'transitionOut'	:  'elastic',
		'speedIn'		:  600,
		'speedOut'		:  200,
		'height'        :  170,
		'width'         :  300,
		'overlayShow'	:  false,
		'type'          :  'iframe'
    });
    
    var params = $("#footerparams").val();

    $.get("/footer.php?c=promotion", function(data) {
        if(typeof(data) == 'string') {
            $("#promotion").html(data);
        } else {
            $("#promotion").html($(data).children());
        }
    });

    $.get("/footer.php?n=" + params, function(data) {
        if(typeof(data) == 'string') {
            $("#newest").html(data);
        } else {
            $("#newest").html($(data).children());
        }
    });

    $.get("/footer.php?b=" + params, function(data) {
        if(typeof(data) == 'string') {
            $("#bestsellers").html(data);
        } else {
            $("#bestsellers").html($(data).children());
        }
    });
    

    $("div.footercell").hover(
        function() {
           $(this).css('border', '1px solid #FF8C00');
           },
        function() {
           $(this).css('border', '1px solid #ccc');
    });


});

