/**
 *
 * @access public
 * @return void
 **/
 /**
  *
  * @access public
  * @return void
  **/


/*function theRotator() {
	//Set the opacity of all images to 0
	$('div.rotator ul li').hide();

	//Get the first image and display it (gets set to full opacity)
	$('div.rotator ul li:first').show();

	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',5000);

}

function rotate() {
	//Get the first image
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));

	//Set the fade in effect for the next image, the show class has higher z-index
	next.addClass('show')
	.show(1000);

	//Hide the current image
	current.hide(1000)
	.removeClass('show');

};*/

function theRotator(object) {
	//Set the opacity of all images to 0
	$(object).children("ul").children("li").hide();;

	//Get the first image and display it (gets set to full opacity)
	$(object).children("ul").find("li:first").show();
 //$('div.rotator ul li:first').show();

	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds


 //setInterval('rotate(object)',5000);
 setInterval(function(){rotate(object);},5000);
//rotate(object);
}

function rotate(object) {
	//Get the first image
	//var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));
	var current = ($(object).children("ul").find('li.show')?  $(object).children("ul").find('li.show') : $(object).children("ul").find('li:first'));
 //alert($(current).html());
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $(object).children("ul").find('li:first') :current.next()) : $(object).children("ul").find('li:first'));
 //alert($(next).html());
	//Set the fade in effect for the next image, the show class has higher z-index


	//Hide the current image
	current.hide()
	.removeClass('show');

	next.addClass('show')
	.show();

};

$(window).load(function(){

});

$(function(){

    $.blockUI.defaults.message ='<img src="images/loading.gif" />';
 			$.blockUI.defaults.css.border = '0px solid #999999';
 			$.blockUI.defaults.css.width = '300px';
 			$.blockUI.defaults.css.textAlign = 'center';
 			$.blockUI.defaults.css.background = 'white';




    //theRotator();
    $(".rotator").each(function(){
        theRotator(this);
    });

    $("#homeExtra").hide();

    $("#more").click(function() {

    $("#homeExtra").slideToggle();

    });

    $("a#fancybox").fancybox({
				'titleShow'		: false
			});



    $(".small").slideUp();
    $(".medium").slideUp();
    $(".large").slideUp();
    $(".xlarge").slideUp();
    $(".oneSize").slideUp();


    $(".size").bind("change", function () {
        if ($(this).val() == "SMALL") {
            $(".small").slideDown();
            $(".medium").slideUp();
            $(".large").slideUp();
            $(".xlarge").slideUp();
        }
        else if($(this).val() == "MEDIUM") {
            $(".medium").slideDown();
            $(".small").slideUp();
            $(".large").slideUp();
            $(".xlarge").slideUp();
        }
        else if($(this).val() == "LARGE") {
            $(".large").slideDown();
            $(".small").slideUp();
            $(".medium").slideUp();
            $(".xlarge").slideUp();
        }
        else if($(this).val() == "XLARGE") {
            $(".xlarge").slideDown();
            $(".small").slideUp();
            $(".medium").slideUp();
            $(".large").slideUp();
        }
        else if($(this).val() == "ONE SIZE") {
            $(".xlarge").slideUp();
            $(".small").slideUp();
            $(".medium").slideUp();
            $(".large").slideUp();
            $(".oneSize").slideDown();
        }
    });


 			(jQuery)("#tickerTapeWrapper").show();

     $(".quickBuy").click(function() {

         var id;
         id = $(this).children("img").attr('id');

         $.get(ROOT_PAGE_PATH+"getVersionsAjax.php", {"id": id},

         function(data)
         {

             var name = data.versions[0].name;
             var description = data.versions[0].shortDescription;

             //alert(name);
             var form;
             form="<div id='oneClickContainer'><div id='oneClickHeader'><h1>Buy Product</h1><span class='close'><a href='#' class='closeOneClick'><img src='"+ROOT_PAGE_PATH+"images/mainSite/close2.jpg'/></a></span></div><div id='oneClickSlice'><h1>"+name+"</h1>"+description+"<br /><br /><p style='color:red;'>There is a lead time for most of our products of around 2-3 weeks.  If you need your award quicker than this please give us a call.</p><br /><form action='' method='post' class='itemAddForm'><table style='width:250px;margin-left:auto;margin-right:auto;' cellspacing='10px'>";

             //For each array row returned. There should be only one in this case
             //$.each(data.versions,function(index,item){
                 var productID = data.versions[0].productID;
                 var price = data.versions[0].price;
                 var engravingID = data.versions[1].engravingID;
                 var engravingPrice = data.versions[1].engravingPrice;
                 var presentationID = data.versions[2].presentationID;
                 var presentationPrice = data.versions[2].presentationPrice;

                 //productID = item.productID;
                 //price = item.price;
                 //engravingID = item.engravingID;
                 //engravingPrice = item.engravingPrice;
                 //presentationID = item.presentationID;
                 //presentationPrice = item.presentationPrice;

                 form = form+"<tr><td>&pound;"+price+"<input type='hidden' name='cartOperation' value='true' /><input type='hidden' name='productID' value='"+productID+"' /></td><td><input type='text' size='1' maxlength='3' name='quantity' value='1' />&nbsp;</td></tr>";
                 form = form+"<tr><td>Engraving - &pound;"+engravingPrice+"<input type='hidden' name='cartOperation' value='true' /><input type='hidden' name='engravingID' value='"+engravingID+"' /></td><td><input type='text' size='1' maxlength='3' name='engravingQuantity' value='0' />&nbsp;</td></tr>";
                 form = form+"<tr><td>Presentation Box - &pound;"+presentationPrice+"<input type='hidden' name='cartOperation' value='true' /><input type='hidden' name='presentationID' value='"+presentationID+"' /></td><td><input type='text' size='1' maxlength='3' name='presentationQuantity' value='0' />&nbsp;</td></tr>";

             //});

             form = form+"</table><input type='image' class='addToCart' src='"+ROOT_PAGE_PATH+"images/mainSite/NewAddToBasket.jpg' name='submit' style='width: 60px; position:relative;top:3px;' /><input type='hidden' name='addItem' value='true' /></form></div>";
             form = form+"<div id='oneClickFooter'></div></div>";

             //REMOVE EXISTING QUICKBUY FORM
             $("#oneClickContainer").remove();
             $("body").append(form);
             $("#oneClickContainer").hide();



             $.blockUI({
                 message: $("#oneClickContainer"),
                 //message: "<p>Hello World</p>",
                 css: {cursor:null, background: 'transparent'},
                 overlayCSS: { backgroundColor: '#ffffff',cursor:null}
             });

             $('.itemAddForm').ajaxForm({
                 dataType:null,
                 success: function(responseText, statusText) {
                     $.unblockUI();

                     $(".basketPreview").show();
                     $(".totalBox").html("Updating");

                     //NOW UPDATE BASKET PREVIEW BY CALLING AJAX SCRIPT TO RETURN JSON FORMATTED CART DATA
                     $.post(ROOT_PAGE_PATH+"getShoppingCartAjax.php",null,function(data){
                         //now update basket preview

                         //remove all rows
                         $(".BasketYSlice table").empty();
                         //alert("Removed - add from adv search or view cat page");

                         //now loop over all items in data
                         $.each(data.items,function(index,item){
                             var row = "<tr><td style='text-align:right;'>"+item.quantity+"x</td><td style='text-align:left;'>"+item.name+"</td><td style='text-align:left;'>&pound;"+item.subTotal+"</td></tr>";
                             $(".BasketYSlice table").append(row);
                         });

                         //now update total
                         // $(".basketPreview .totalBox .middleBar").html("Total &pound;"+data.total);
                         $(".totalBox").html("&pound;"+data.total);
                         //now update basket count
                         $('.cartText').html(data.cartText);

                         $(".basketEmptyText").empty();

                         /* Not required now
                         $(".basketLink").click(function(){
                              $(".basketPreview").slideToggle(500);
                              return false;
                         });*/

                     },"json");
                 }
             });


             $(".closeOneClick").click(function() {
                $.unblockUI();
             });


         }, "json");
         return false;
     });



     function show() {
         var menu = $(this);
         menu.children(".actions").slideDown();
       }

       function hide() {
        var menu = $(this);
        menu.children(".actions").slideUp();
      }

      $(".hover-menu").hoverIntent({
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
        interval: 50,   // number = milliseconds for onMouseOver polling interval
        over: show,     // function = onMouseOver callback (required)
        timeout: 300,   // number = milliseconds delay before onMouseOut
        out: hide       // function = onMouseOut callback (required)
      });

      $('#searchShop').focus(function(){
          if(this.value=='Search Site')
          {
            this.value=''
          }
    });


});


