var activePrice = ''; // current showing price comparison popup id
var loadedPrice = {}; // object of price popups already loaded 

var activeImg = ''; // current showing image
var loadedImg = {}; // object of price images already loaded 
var loadSuccess = false;
var posterTimeoutHandle
function show_price_compare(id){
    var   divId = 'compare_'+id;
    //var  loadingDiv = 'loading_compare_'+id;
    if(activePrice != '' && activePrice != divId){
	new Effect.Fade(activePrice, {duration:0});
    }
    if(loadedPrice[divId]==1){ //if ajax query has already been called, then just show the div
	activePrice = divId;
	new Effect.Appear(divId, {
            duration:0
	});
    }
else{ //if query hasn't been called, then initialize ajax.updater and load the price comparison
    Element.show('spinner_image'+id);
    activePrice = divId;        
    document.getElementById("iframe1").src="/compare_price?id="+id;
    loadedPrice[divId] = 1;
}
   
}


function generate_compare_price_htmls(type_id,product_id){
var cobrand_id = '1306';
var rating_star_type = 1;
var cb_limit = 6;
var open_link_type2 = 1;
var show_link_price2 = 1;
var head_title_type = '1';
document.write('<scr'+'ipt src="http://ah.pricegrabber.com/cb_table.php?'+
    type_id+'='+product_id+
    '&dw=1'+
    '&cobrand_id='+cobrand_id+
    '&rst='+rating_star_type+
    '&slp='+show_link_price2+
    '&olt='+open_link_type2+
    '&l='+cb_limit+
    '&htt='+head_title_type+
    '"></scr'+'ipt>');
}

function loadsucc(id,content)
{
    
if(content.match(new RegExp('cb_table_main', 'img'))){
    var cssFragment='(?:<style>)((\n|\r|.)*?)(?:</style>)';
    var docHead=document.getElementsByTagName("head")[0];
    var css = content.match(new RegExp(cssFragment, 'img'));
    if(css){
        css=css.toString();
        var re = /(?:<style.*?id=[\"\'](.*?)[\"\'].*?>)([\S\s]*?)(?:<\/style>)|(?:<style>)([\S\s]*?)(?:<\/style>)/ig;
        var match;
        while(match = re.exec(css)){
            if(match[2]||match[3]){
                var s0 = document.createElement("style");
                var t;
                if(match[1]){
                    var e=document.getElementById(match[1]);
                    if(e)e.parentNode.removeChild(e);
                    s0.setAttribute("id", match[1]);
                }
                s0.setAttribute("type","text/css");
                if(match[2]) t=match[2];
                if(match[3]) t=match[3];
                if(s0.styleSheet)s0.styleSheet.cssText=t;//IE
                else s0.appendChild(document.createTextNode(t));//W3C
                docHead.appendChild(s0);
            }
        }
    }
    loadSuccess = true
    $("compare_"+id).update(content.replace(new RegExp(cssFragment, 'img'),"")); 
    Element.hide('spinner_image'+id);
    $("compare_"+id).style.display="block";
}else{
    
    Element.hide('spinner_image'+id);
}
}

function setTimeoutHandle(_id){
posterTimeoutHandle = setTimeout("close_price_compare('"+_id+"');", 100);   
}


function clearTimeoutHandle(){
if(posterTimeoutHandle){
    clearTimeout(posterTimeoutHandle);
}
}

function show_price_grabber_info(id,img_url){        
var divId = 'pricegrabber_info_'+id;   
var img ;
    
if(activeImg != '' && activeImg != divId){
    new Effect.Fade(activeImg, {duration:0});
}
if(loadedImg[divId]==1){ //if ajax query has already been called, then just show the div
    activeImg = divId;
    new Effect.Appear(divId, {
        duration:0
    });
}
else{ //if query hasn't been called, then initialize ajax.updater and load the price comparison
    if (/http/i.exec(img_url)){            
        activeImg = divId;        
        img = document.createElement("img");
        img.src = img_url;
        $(divId).appendChild(img);
        loadedImg[divId] = 1;
        new Effect.Appear(divId, {
            duration:0
        });
    }
}
}


function close_price_compare(_id){
new Effect.Fade(_id, {duration:0})
}


function mouseout(event,_id,eElem){
e = event ? event : window.event;
event_node = e.relatedTarget ? e.relatedTarget : e.toElement;
while(event_node != eElem && event_node.nodeName != 'BODY'){
    event_node = event_node.parentNode;
} 
if(event_node != eElem){
    close_price_compare(_id); 
} 
return false;    
} 