$(document).ready(function() {

    /* Hover effect on just add list */
    $("#just-add-items li").hover(
      function() {$(this).addClass("highlight");},
      function() {$(this).removeClass("highlight");}
    );

    /* External links to open in a new window */
    $('a[rel="external"]').click(function() {
        window.open($(this).attr('href'));
        return false;
    });

    /* Tooltip code - Product page features*/
    $(function() {
        $('#TZ1 .photos li').each(function() {
            var distance = 10;
            var time = 500;
            var timeOut = 500;
            var hideDelay = 50;
            var imgOffset = 25;

            var hideDelayTimer = null;
            var hover_intent;

            var beingShown = false;
            var shown = false;

            var trigger = $('.info', this);
            var info = $('.tooltip', this).css('opacity', 0);
            var nav = $('#mainNav');

            var imgHeight = $("img", info).attr('height');
            var imgWidth = ($("img", info).attr('width') / 2);

            $([trigger.get(0), info.get(0)]).mouseover(function(e) {
                $(this).parent().addClass("highlight");
                //alert(trigger.parent().offset().left);

                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    //Intenional mouseover timer - prevent accidental triggering of tooltip
                    hover_intent = setTimeout(function() {
                        //Left position for the tooltip
                        var leftPos = e.pageX - trigger.offset().left - imgOffset;
                        leftPos = trigger.offset().left - imgWidth;
                        leftPos = trigger.parent().offset().left;

                        // reset position of info box
                        beingShown = true;
						
						//ie tooltip going behind other product - set z-index
						$('#TZ2').css({"z-index": "-9999"});
						
                        info.css({
                            top: -12 - imgHeight,
                            left: -15,
                            display: 'block',
							"z-index": "9999"
                        }).animate({
                            top: '-=' + distance + 'px',
                            opacity: 1
                        }, time, 'swing', function() {
                            beingShown = false;
                            shown = true;
                        });
                    }, 200);
                }
                return false;
            }).mouseout(function() {
                $(this).parent().removeClass("highlight");

                //Clear intenional mouseover timer
                try { clearTimeout(hover_intent); } catch (e) { };

                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function() {
                    hideDelayTimer = null;
									
                    info.animate({
                        top: '+=' + distance + 'px',
                        opacity: 0
                    }, timeOut, 'swing', function() {
                        beingShown = false;
                        shown = false;
                        info.css('display', 'none')
						//ie tooltip going behind other product - reset z-index
						$('#TZ2').css({"z-index": "0"});;
                    });
                }, hideDelay);
				
                return false;
            });
        });
    });
	
	
    $(function() {
        $('#TZ2 .photos li').each(function() {
            var distance = 10;
            var time = 500;
            var timeOut = 500;
            var hideDelay = 50;
            var imgOffset = 25;

            var hideDelayTimer = null;
            var hover_intent;

            var beingShown = false;
            var shown = false;

            var trigger = $('.info', this);
            var info = $('.tooltip', this).css('opacity', 0);
            var nav = $('#mainNav');

            var imgHeight = $("img", info).attr('height');
            var imgWidth = 100 - ($("img", info).attr('width'));

            $([trigger.get(0), info.get(0)]).mouseover(function(e) {
                $(this).parent().addClass("highlight");

                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    //Intenional mouseover timer - prevent accidental triggering of tooltip
                    hover_intent = setTimeout(function() {
                        //Left position for the tooltip
                        var leftPos = e.pageX - trigger.offset().left - imgOffset;
                        leftPos = trigger.offset().left - imgWidth;
                        leftPos = trigger.parent().offset().left;

                        // reset position of info box
                        beingShown = true;
                        info.css({
                            top: -12 - imgHeight,
                            left: imgWidth,
                            display: 'block',
							"z-index": "9999"
                        }).animate({
                            top: '-=' + distance + 'px',
                            opacity: 1
                        }, time, 'swing', function() {
                            beingShown = false;
                            shown = true;
                        });
                    }, 200);
                }
                return false;
            }).mouseout(function() {
                $(this).parent().removeClass("highlight");

                //Clear intenional mouseover timer
                try { clearTimeout(hover_intent); } catch (e) { };

                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function() {
                    hideDelayTimer = null;
                    info.animate({
                        top: '+=' + distance + 'px',
                        opacity: 0
                    }, timeOut, 'swing', function() {
                        beingShown = false;
                        shown = false;
                        info.css('display', 'none');
                    });
                }, hideDelay);
                return false;
            });
        });
    });

	if ($.browser.msie && $.browser.version < 7) {	
		//Assign class to p tags in content-inner for the transparent bg. avoid lag effect.
		$('#content-inner p').each(function(){
			$(this).addClass('trans');	
		});
		
		//Fix PNG transparency
		DD_belatedPNG.fix('.model');
		DD_belatedPNG.fix('p');
		
		/* Move model back to original place once transparentcy fixed */
	 	$('.model').css({right: 0});
	}
});
