
var browser = GetBrowserInfo();

var quickviewBigURL = '';
var quickviewSmlURL = '';

if(browser.objIE.IsIE && (browser.objIE.IsIE4 || browser.objIE.IsIE5 || browser.objIE.IsIE5_5 || browser.objIE.IsIE6)) {
    // does not support png images, use gif
    quickviewBigURL = '/images/global/listing/btn_quickView_ie6.gif';
    quickviewSmlURL = '/images/global/listing/btn_OTQuickView_listing.gif';
} else {
    // supports png images
    quickviewBigURL = '/images/global/listing/btn_quickView.png';
    quickviewSmlURL = '/images/global/listing/btn_quickView_sml.png';
}

var activeImage = ''; 
var image =  new Class.create({
	initialize: function(id) {
		this.id = id;
		this.isListingButton = false; 
		this.familyId=id.substring(5);
		if($(id))
		{
			Event.observe(id,'mouseover', this.OverlayShow);
			Event.observe(id,'mouseout', this.OverlayHide);
		}
	},
	OverlayShow: function(event){
	    var imageoffset = 39; 
	    var cImg = $(this.id);
	    var imageXoffSet = 0;
	    
	    if (cImg.width == 140 && cImg.height == 140)
	    {
	        // Large product image (e.g. gallery)
	        imageXoffSet = -30;
	    } 
	    else if (cImg.width == 120 && cImg.height == 120)
	    {
	        // Medium size image (e.g. Last items aired)
	        imageXoffSet = 0
	    }
	    else
	    {
	        imageXoffSet = 0;    
	    } 
	    
	    if(cImg.width > 100 )
	    {
	        //alert(quickviewBigURL);
            $(quickViewButton.id+'Img').src = quickviewBigURL;
            this.isListingButton = false;
            imageoffset = 42             
        }
	    else
	    {
	        //alert(quickviewSmlURL);
	        $(quickViewButton.id+'Img').src = quickviewSmlURL; 
	        this.isListingButton = true; 
	    }

	    
		var imagepos = $(this.id).viewportOffset();
		var windowPos = document.viewport.getScrollOffsets();
		var x = ((imagepos.top+windowPos.top+$(this.id).height*.70)+imageXoffSet  );
		var y = imagepos.left+windowPos.left+$(this.id).width*.50 - imageoffset;
		$(quickViewButton.id).style.top = x + 'px';
		$(quickViewButton.id).style.left= y + 'px';
	
		$(quickViewButton.id).show();
		activeImage = this.id; 
		},
	OverlayHide: function (event){
		$(quickViewButton.id).hide();
	 
	}
});
var underlay = null; 

function SetOverlayForImages(){

		underlay = new image('underlay');
		var images = $$('img');
		for(var i = 0; i<images.length; i++)
		{
			if(images[i].name == 'imgProduct')
			{
			new image(images[i].id);
			}
		}
	}
	Event.observe(window,'load',SetOverlayForImages);


var button =  new Class.create({

	initialize: function(id) {
		this.id = id; 
		Event.observe(this.id,'mouseover', this.highlight);
		Event.observe(this.id,'mouseout', this.unhighlight);
		Event.observe(this.id,'click', this.click);
		$(this.id).hide();
	},
	highlight: function(event){
		//$('activeImage').stopObserving('mouseover', underlay.OverlayShow);	
		$(activeImage).stopObserving('mouseout', underlay.OverlayHide);
		
		$(this.id).show()
		//$(this.id + 'Img').src = "/images/stylesheetimgs/btn_quickViewOver.gif"; 
		//$(this.id + 'Img').src = "/images/global/listing/btn_OTQuickView.gif"; 
		
		},
	unhighlight: function (event){
		//$(this.id + 'Img').src = "/images/stylesheetimgs/btn_quickView.gif";
		//$(this.id + 'Img').src = "/images/global/listing/btn_OTQuickView.gif";
		$(activeImage).observe('mouseout', underlay.OverlayHide);
		//$(activeImage).observe('mouseout', underlay.OverlayShow); 
	},
	click: function(event){
		var title = $(activeImage).title; 
		if (title.length == 0)
		{
		   title = $(activeImage).alt; 
		}
		var familyId = title.substring(0,title.indexOf(' ')); 
		quickView.LoadQuickView(familyId, event);
	}
});


