
var overArea = false;
var overDisplay = false;

document.observe("dom:loaded",function(event){
    if($("cart_hover")) {
        $("cart_hover").observe("mouseover",function(event){
            $("cart_display").show();
            overArea = true;
        });

        $("cart_hover").observe("mouseout",function(event){
            overArea = false;
            setTimeout("hideCartDisplay();",50);    // Allows for the alternate "mouseover" event to be called
        });
    }

    if($("cart_display")) {
        $("cart_display").observe("mouseover",function(event){
            overDisplay = true;
        });

        $("cart_display").observe("mouseout",function(event){
            overDisplay = false;
            setTimeout("hideCartDisplay();",50);    // Allows for the alternate "mouseover" event to be called
        });
    }

    // register any preview elements.    
    var list = $$("img[name=preview]");
    if( list.length > 0 ) {
        // SUCCESS!  I believe I've removed the need for this mousemove crap, leaving it  here just in
        // case Ive missed something. :D
        // only set the mousemove handler if there are preview elements
        // IE = document.all?true:false
        // if (!IE) document.captureEvents(Event.MOUSEMOVE)
        // document.onmousemove = getMouseXY;
        
        // register previews!
        list.each(observePreview);
    }
    
    $("main_popup_close").observe("click",main_popup_close);

    $$("[name=green_bug_hover]").each(function(el,idx) {
        el.observe("mouseover", function(ev) {
            is_hovering_green_bug = true;
            setTimeout("toggle_green_bug(true);", .2);
        });
        
        el.observe("mouseout", function(ev) {
            is_hovering_green_bug = false;
            setTimeout("toggle_green_bug(false);", .2);
        });
    });

});


var is_hovering_green_bug = true;

function toggle_green_bug(state) {
    if(state) {
        $("green_bug").show();
    } else {
        if(!is_hovering_green_bug) {
            $("green_bug").hide();
        }
    }
}


function hideCartDisplay() {
    if(!overArea && !overDisplay) {
        $("cart_display").hide();
    }
}


function showpreview(file){
    if(file!="noimage-Back.png"){
//     $('previmgdisplay').setStyle( { backgroundImage:  'url(http://app.bepo3.com/asitool/images/previews/'+file+')'} );
        $("previmgtag").writeAttribute("src",file);
    }
}

function openPreviewWindow() {
    if($("previmgtag").readAttribute("src") != "") {
        // Required to use .width in place of prototype getWidth as getWidth returns
        // the "calculated width" which is 0 while hidden
        $('prevwin').appear({ duration: .4 });
        // it's taking some time for the dom to be updated with the new height of the image so,
        // try it in a few ms after the thing is told to appear
        setTimeout("$('prevwin').setStyle( {top: (tempY - $('previmgtag').getHeight()/2)+'px'} );",50);
    }
}

function toggleprev(){
  if(document.getElementById('prevwin').style.display=='none'){
     $('prevwin').appear({ duration: .5 });
  } else {
     $('prevwin').fade({ duration: .5 });
  }
}


// I'd like to see if this code can be reduced/removed.  document.captureEvents is DEPRECATED
// so I'd especially like to get rid of that.  Need an IE machine to work with.
<!--
//var IE = document.all?true:false
//if (!IE) document.captureEvents(Event.MOUSEMOVE)
//document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
var popupHeight = 260;
var popupWidth = 260;

//function getMouseXY(e) {
//  if (IE) { // grab the x-y pos.s if browser is IE
//     tempX = event.clientX + document.body.scrollLeft
//     tempY = event.clientY + document.body.scrollTop
//  } else {  // grab the x-y pos.s if browser is NS
//     tempX = e.pageX
//     tempY = e.pageY
//  }
//}
//-->

/*
// helper functions to register preivews on image elements.
function observePreview(el,index) {
    el.observe("click",handlePreviewClick);
}

function handlePreviewClick(ev) {
    var vp = document.viewport.getScrollOffsets();
    tempX = ev.clientX + vp[0];
    tempY = ev.clientY + vp[1];

    path = ev.element().readAttribute("src");
    //path = path.split("/");
    //path = path.pop();
    
    showpreview(path);
}
*/

function main_popup_close(ev) {
    $("main_popup_container").fade({duration:.4});
}

// Recaptcha
var RecaptchaOptions = {
	theme : 'white',
	lang : 'es'
};


