﻿$(document).ready(function(){
    
    $('#deals-mostViewed').css({"display":"inline"});
    $('#deals-priceCrash').css({"display":"inline"});
    
    if(!($.browser.msie && $.browser.version.substr(0,1)<7))
    {	
        $('.js-carousel-top').jcarousel({
            scroll: 4
        });
    	
        $('.js-carousel-bottom').jcarousel({
            scroll: 4
        });
    }
		
		$('#homeTopRow .action').hover(
			function(){
				$(".choices", this).stop().animate({top:'0'},{queue:false,duration:300});
				$(this).removeClass('js-action-not-selected');
				//$(this).parent().find(".js-action-not-selected").animate({opacity:0.2}, 0);
			},
			function() {
				$(".choices", this).stop().animate({top:'186px'},{queue:false,duration:200});
				//$(this).parent().find(".js-action-not-selected").animate({opacity:1}, 0);
				$(this).addClass('js-action-not-selected');
			}
			
		);
		
		$('#homeTopBannerRotator').cycle({ 
			fx:     'fade', 
			timeout: 6000,
			speed: 2000, 
			after: null,
			prev: '#prev',
            next: '#next'
		});	
		
	
		$('#justAddedProducts').cycle({ 
			fx:     'fade', 
			timeout: 4000,
			speed: 2000, 
			prev: '#justAdded .previous',
            next: '#justAdded .next',
            sync: 0
		});
		
    $('.js-deals-tab').click(function(){  
        
        var _self = this;     
        
        $('.js-deals-tab').removeClass('selected');
        
        $('.scrollbox', 'div').html('');
        $('.scrollbox', 'div').addClass('loading');
        
        var elementId = $(_self).attr('id').substr(6, $(_self).attr('id').length - 6);
        $('#deals-tab-container', 'div').removeClass();
        $('#deals-tab-container', 'div').addClass(elementId);
        
        $.ajax({
            type: 'GET',
            url: '/handlers/homepage/dealstabs.ashx?tab=' + elementId,
            dataType: 'html',
            success: function(data){
                $(_self).addClass('selected');
                $('.scrollbox', 'div').removeClass('loading');
                $('.scrollbox', 'div').html(data);
            }
        });                
        
        return false;
    });
    
    $('.slideShow').cycle({
	    pause: true ,
	    speed: 'fast',
	    timeout: 8000,
	    pager: '#slideShowNav',
        pagerEvent: 'mouseover', 
	    pagerAnchorBuilder: function(idx, slide) { 
			
	        var itemNo = (idx + 1);
			
			if(idx == 1)
			{
		        return '<li class="wanted"><a href="' + $('.js-slide-link', slide).attr('href') + '" id="ref0' + itemNo + '" class="nav arrow' + itemNo + '">'+ $(slide).attr('title') +'</a></li>';
			}
			else
			{			
		        return '<li><a href="' + $('.js-slide-link', slide).attr('href') + '" id="ref0' + itemNo + '" class="nav arrow' + itemNo + '">'+ $(slide).attr('title') +'</a></li>';
		    }
        }
    });

    $('a.nav').mouseover(function(){
        $('.slideShow').cycle('pause');
    });
    
    $('a.nav').mouseout(function(){
        $('.slideShow').cycle('resume');
    });
    
    $('.js-qtip').each(function () {
      var _self = $(this);
      
      _self.qtip({ 
        position: {
          corner: {
            target: 'topMiddle',
            tooltip: 'bottomMiddle'
          },
          adjust: {
            y: 10
          }
        },
       style: { 
          background: '#ffffff',
          width: 150,
          color: '#005AAB',
          textAlign: 'center',
          border: {
             width: 2,
             radius: 2,
             color: '#005AAB'
          }, 
          title: { 
            background: '#ffffff',
            textAlign: 'center'
          },
          tip: true 
        },
        content: {
           text: $(_self).attr('title'),
           title: { text: $('img', _self).attr('alt') }
        },
        show: {
            delay: 0,
            effect: {
                length: 0
            }
        }
      });    
   });
});
