jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ((jQuery(window).height() - this.outerHeight()) / 2) + jQuery(window).scrollTop() + "px");
    this.css("left", ((jQuery(window).width() - this.outerWidth()) / 2) + jQuery(window).scrollLeft() + "px");
  //  alert('asd');
    return this; 
}



jQuery(document).ready(function() {

	jQuery(".ptkaLimiterCurrent a").click(
		function(){
				jQuery(this).closest(".ptkaLimiter").find("ul").toggle("slide", { direction: "up" }, 300);
				return false;
			}
		);
	
	jQuery(".ptkaSorterCurrent a").click(
			function(){
					jQuery(this).closest(".ptkaSorter").find("ul").toggle("slide", { direction: "up" }, 300);
					return false;
				}
			);
	
	//jQuery(".ptkaGridProductBottom").hover(function (){jQuery(this).effect('bounce');});
	
	jQuery(".ptkaTopCartContainer h2 a").hover(function (){
		if(jQuery("#cartPreview").length){
			jQuery("#cartPreview").fadeIn();
			jQuery(".col-right").fadeOut();
		}
	});
	
	jQuery("#cartPreview").mouseleave(function (){
		jQuery("#cartPreview").fadeOut();
		jQuery(".col-right").fadeIn();
	});

	jQuery(".ptkaCartTableQtyAddLink").click(
			function(){
				var inp = jQuery(this).closest(".ptkaCartTableQty").find("input");
				if(parseInt(inp.val()) < 99)
				{
					inp.val(parseInt(inp.val()) + 1);
				}
				jQuery(".cartLoader").show();
				jQuery(".cartQtyInput").hide();
        
				jQuery(this).closest("form").submit();
				//jQuery('.ptkaCartWait').show();
				return false;
			}
		);
	
	jQuery(".ptkaCartTableQtyRemoveLink").click(
			function(){
				var inp = jQuery(this).closest(".ptkaCartTableQty").find("input");
				
				if(parseInt(inp.val()) > 0)
				{
					inp.val(parseInt(inp.val()) - 1);
				}
				
				jQuery(this).closest("form").submit();
				jQuery('.ptkaCartWait').show();
				return false;
			}
		);
	
	jQuery('.ptkaAdd2CartHomeButton').hover(
            function(){ 
                jQuery(this).addClass('ptkaAdd2CartHomeButtonHover');
            },
            function(){ 
                jQuery(this).removeClass('ptkaAdd2CartHomeButtonHover');    }
        );
	
	if(jQuery('#slider').length)
	{
		jQuery('#slider').innerfade({
        speed: 1000,
        timeout: 5000,
        type: 'sequence',
        containerheight: 	'355px',
        slide_timer_on: 	'yes',
        slide_ui_text:		null,
       	pause_button_id: 	null,
       	slide_nav_id:		'slide_nav',
        slide_ui_parent: 	'slider'
    	});
		
		jQuery.setOptionsButtonEvent();
	}
	
	//messages fadout
	setTimeout(function(){jQuery('ul.messages').fadeOut('slow');},5000); 
    
    jQuery("#ptkaLoginBoxLink").click(function () { 
        jQuery("#ptkaLoginBoxBottom").slideToggle(); 
        return false;
      });
    
    jQuery("#ptkaLoginBoxCheckoutLink").click(function () { 
        jQuery("#ptkaLoginBoxBottom").slideToggle(); 
        return false;
      });
    
     /* jQuery("#ptkaMaleLink").click(function () { 
    	  jQuery(".ptkaSubSearchBarContainer").show();
          jQuery(".ptkaSubSearchBarContainerF").fadeOut(0); 
    	  jQuery(".ptkaSubSearchBarContainerM").fadeIn();
    	  jQuery(".ptkaSubSearchBarContainerA").fadeOut(0);
        return false;
      }, function() {
		jQuery(".ptkaSubSearchBarContainerM").stop().css('opacity', 1);
	});

      jQuery("#ptkaFemaleLink").click(function () { 
    	  jQuery(".ptkaSubSearchBarContainer").show();
          jQuery(".ptkaSubSearchBarContainerF").fadeIn();
          jQuery(".ptkaSubSearchBarContainerM").fadeOut(0); 
          jQuery(".ptkaSubSearchBarContainerA").fadeOut(0);
        return false;
      }, function() {
		jQuery(".ptkaSubSearchBarContainerF").stop().css('opacity', 1);
	 });
      
      jQuery(".subSearchBarFHideLink").click(function () { 
    	  jQuery(".ptkaSubSearchBarContainerF").fadeOut();
    	  return false;
      });
      
      
      jQuery("#ptkaAddonsLink").click(function () { 
        jQuery(".ptkaSubSearchBarContainer").show();
          jQuery(".ptkaSubSearchBarContainerF").fadeOut(0);
          jQuery(".ptkaSubSearchBarContainerM").fadeOut(0);  
        jQuery(".ptkaSubSearchBarContainerA").fadeIn();
        
        return false;
      }, function() {
		jQuery(".ptkaSubSearchBarContainerA").stop().css('opacity', 1);
	});
      
       jQuery(".subSearchBarAHideLink").click(function () { 
        jQuery(".ptkaSubSearchBarContainerA").fadeOut();
        return false;
      });*/
      
      jQuery('body').click(function(event) {
       
        if (!jQuery(event.target).closest('.ptkaSubSearchBarContainer').length 
            && !jQuery(event.target).closest('#ptkaAddonsLink').length
            && !jQuery(event.target).closest('#ptkaFemaleLink').length
            && !jQuery(event.target).closest('#ptkaMaleLink').length
            ) {
            jQuery('.ptkaSubSearchBarContainer').hide().children().removeAttr('style');
console.log('hide');
         };
        
         if (!jQuery(event.target).closest('#cartPreview').length) {
           jQuery('#cartPreview').hide();
        };
        
  });

      
     /* jQuery(".ptkaSubSearchBarContainerF").mouseleave(function () { 
        jQuery(".ptkaSubSearchBarContainerF").delay(10000).fadeOut();
        return false;
      });
      
     
      jQuery(".ptkaSubSearchBarContainerF").mouseenter(function () { 
        jQuery(".ptkaSubSearchBarContainerF").clearQueue();
        jQuery(".ptkaSubSearchBarContainerF").fadeIn();
        return false;
      });*/
      
      jQuery(".subSearchBarMHideLink").click(function () { 
    	  jQuery(".ptkaSubSearchBarContainerM").fadeOut();
    	  return false;
      });

  jQuery('.ptkaSearchButtonImage').hover(
              function(){ 
                  jQuery(this).attr({ src : 'images/ptka_top_search_button2.png'});
              },
              function(){ 
                  jQuery(this).attr({ src : 'images/ptka_top_search_button2.png'});             }
          );

  jQuery('#brandSelectionFormFButton').click(
	  function(){
	  jQuery(location).attr('href',jQuery('#brandSelectionFormF select').val());
	  return false;
  });

  var name = "#outerFloatFace";  
	var menuYloc = null;  

	if(jQuery(name).length > 0){
	  
	
	jQuery("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
	
	menuYloc = parseInt(jQuery(name).css("top").substring(0,jQuery(name).css("top").indexOf("px")))  
	jQuery(window).scroll(function () {  
		var offset = menuYloc+jQuery(document).scrollTop()+"px";  
		jQuery(name).animate({top:offset},{duration:500,queue:false});  
	});  
	
	
	jQuery("#outerFloatFace a").hover(function (){jQuery("#innerFloatFace").fadeIn()});
	jQuery("#innerFloatFace").mouseleave(function (){jQuery("#innerFloatFace").fadeOut()});
	} 
	
	
	 jQuery(".ptkaRolloverContainer a.over").fadeOut(); 
	
	jQuery(".ptkaRolloverContainer").hover(function() {  
		
			jQuery(this).find("a.normal").stop().fadeTo(500, 0);
			jQuery(this).find("a.over").stop().fadeTo(500, 1);
         },function() {  
        	     jQuery(this).find("a.normal").stop().fadeTo(500, 1);
 			          jQuery(this).find("a.over").stop().fadeTo(500, 0);
 			        
         }); 
	
	//jQuery("#ptkaCartForm").change(function(){
	//	jQuery("#ptkaCartForm").submit();
	//});
	
	
 jQuery("#s_method_orbainpost_wire").click(function(){jQuery("select").hide("fast");}); 
 
 
});


function agreementOnClick()
{
	var ch = jQuery('#agreementCheckbox').attr('checked');
	if(ch)
	{
		jQuery('#advice-required-agrrement').fadeOut();
	}
	else
	{
		jQuery('#advice-required-agrrement').fadeIn();
	}
	
	return false;
};

function confrimOnClick()
{
	var ch = jQuery('#agreementCheckbox').attr('checked');
	
	if(ch)
	{
		
		review.save();
	}
	else
	{
		jQuery('#advice-required-agrrement').effect("pulsate", {}, 500);
		
	}


	return false;
};



function registerOnClick()
{
	var ch = jQuery('#agreementCheckbox').attr('checked');
	
	if(ch)
	{
		dataForm.submit();
	}
	else
	{
		jQuery('#advice-required-agrrement').effect("pulsate", {}, 500);
		
	}
	
	return false;
};






