$(document).ready(function() {	
	//商品对比
	var cbCompare = $('input[@name=auction_id]');
	cbCompare.attr('checked',false);
	cbCompare.each(function(){
	    var objCurCb = $(this);
	    objCurCb.click(function(){
	        var compareIDs = $('#compareImg').data('pids');
	        var currPID = $(this).val();
	        if(compareIDs){
	            compareIDs = compareIDs;
	        }else{
	            compareIDs = '';
	        };
            if($(this).attr('checked')){
                if(compareIDs == ''){
                    compareIDs += currPID;
                }else{
                    compareIDs += ',' + currPID;
                };
	            if(compareIDs.split(',').length > 3){alert('最多只能选择三个对比商品');return false};
                var strItem = $('<li id="check_' + currPID + '"><a title="删除" class="close"></a>' + $(this).attr('pname') + '</li>');
                strItem.find('.close').click(function(){
                    objCurCb.attr('checked',!objCurCb.attr('checked')).click();
                    objCurCb.attr('checked',!objCurCb.attr('checked'));
                });
                $('#comProlist').append(strItem);
            }else{
                compareIDs = ',' + compareIDs + ',';
                compareIDs = compareIDs.replace(',' + currPID + ',',',');
                compareIDs = compareIDs.substring(1);
                if(compareIDs != ''){
                    compareIDs = compareIDs.substring(0,compareIDs.length-1);
                };
                $('#check_'+currPID).remove();
            };
            $('#compareImg').data('pids',compareIDs);
            if(compareIDs == ''){
                $('#compareContent').hide();
            }else{
                $('#compareContent').show();
                //$(window).scroll();
            };
    	    
	    });
	});
	
	//清空
	$('#compareClose').click(function(){
	    $('#comProlist').html('');
	    $('#compareContent').hide();
	    $('#compareImg').data('pids','');
	    cbCompare.attr('checked',false);//cbCompare是全局变量
	});
	
	$('#compareImg').click(function(){
	    if($('#compareImg').data('pids').split(',').length > 3){alert('最多只能选择三个对比商品');return false};
	    if($('#compareImg').data('pids') && $('#compareImg').data('pids') != ''){
	        var newwin=window.open("","Compare","status,scrollbars,resizable");
		    if(document.all){
			    newwin.moveTo(0,0)
			    newwin.resizeTo(screen.width,screen.height)
		    }
		    newwin.location=baseUrl+'Compare.aspx?pids='+$('#compareImg').data('pids');
		    newwin.focus();
		}
	});
	
	//IE6不支持position: fixed;
	if($.browser.msie && $.browser.version=='6.0'){
	    var obj = $('#compareContent');
	    var cssTop = obj.css('top');
	    $(window).scroll(function(){
	        var scrollheight = document.documentElement.scrollTop;
	        var objTop = parseInt(scrollheight) + parseInt(cssTop);
	        $('#compareContent').css({
	            'position':'absolute',
	            'top':objTop
	        });
	    });
	}
});
