var cbox_opts = {
    inline:true,
    href:'#orderform_container',
    height:'90%',
    preloading:false,
    overlayClose:false,
    open:true,
    width:'660px',
    title:'Place Order Below',
    html:false,
    opacity:'0.85',
    onOpen:cbox_open,
    onLoad:cbox_load,
    onComplete:cbox_complete,
    onCleanup:cbox_cleanup,
    onClosed:cbox_closed
}

$("a.thickbox, area.thickbox, input.thickbox").live("click", function() {
    $.fn.colorbox(cbox_opts);
    return false;
});

$(document).ready(function() {
	if(location.hash == "#order") {
		$.fn.colorbox(cbox_opts);
	}
});

function cbox_resize() {
	$.fn.colorbox.load();
}

function cbox_open() {
	return false;
}

function cbox_load() {
	$(document).unbind("keydown.cbox_close").unbind("keydown.cbox_arrows");
	$(window).keydown(function(e) { if(e.keyCode == 38 || e.keyCode == 40) { return false; } });
	if($.browser.msie == true && parseInt($.browser.version) == 6) {
		$("body, html").css({ height:'100%', width:'100%' });
		$("html").css("overflow","hidden");
	} else {
		$("html").css('overflow', 'hidden');
	}
	hide_flash(true);
}

function cbox_complete() {
	$(window).resize(cbox_resize);
}

function cbox_cleanup() {
	return false;
}

function cbox_closed() {
	if($.browser.msie == true && parseInt($.browser.version) == 6) {
		$("body, html").css({ height:'auto', width:'auto' });
		$("html").css('overflow', '');
	} else {
		$("html").css('overflow', 'auto');
	}
	hide_flash(false);
	$(window).unbind('keydown');
	$(window).unbind('resize');
}

function hide_flash(hide) {
    if($.browser.msie == true) {
        for(var x=0; x<mplayers.length; x++) {
            try {
                mplayers[x].sendEvent("PLAY", false);
            } catch(err) {}
        }  
    } else {   
        var objects = $('object');
        var embeds = $('embed');
        if(hide) {
            objects.css({ visibility:'hidden', display:'none' });
            embeds.css({ visibility:'hidden', display:'none' });
        } else {
            objects.css({ visibility:'visible', display:'block' });
            embeds.css({ visibility:'visible', display:'block' });
        }
    }
    return false;
}

function showobj(obj) {
	var objstr = '';
	for(prop in obj) objstr += prop + ": " + obj[prop] + "\n";
	alert(objstr);
}

function tb_show(caption, url, imageGroup) {
    var old_tb = url.substr(url.indexOf('?')+1).toLowerCase().split('&');
    var new_cbox = new Array();
    for(var i=0; i<old_tb.length; i++) {
        var pieces = old_tb[i].split('=');
        if(pieces[0] == "height") {
            new_cbox[0]=pieces[1]+'px';
        } else if(pieces[0] == "width") {
            new_cbox[1]=pieces[1]+'px';
        } else if(pieces[0] == "inlineid") {
            new_cbox[2]='#'+pieces[1];
            new_cbox[3]=pieces[1];
        }
    }

    if($('.old_tb_element_wrapper_'+new_cbox[3]).length < 1) {
        $(new_cbox[2]).wrap('<div class="old_tb_element_wrapper_'+new_cbox[3]+'" />');
        $('.old_tb_element_wrapper_'+new_cbox[3]).hide();
        $(new_cbox[2]).show();
    }

	$.fn.colorbox({
        inline:true,
        preloading:false,
        overlayClose:false,
        open:true,
        title:'Place Order Below',
        html:false,
        height:new_cbox[0],
        width:new_cbox[1],
        href:new_cbox[2]
    });
    return false;
}

function tb_show_ext(caption, url, imageGroup) {
    tb_show(caption, url, imageGroup);
}

function tb_remove() {
    $.fn.colorbox.close();
    return false;
}

// BEGIN -- FOLLOWING CODE ENABLES SIDE IMAGES ON CB WINDOW
var side_imgs = false;
$(document).ready(function() {
    if($('#cb_left_image').length > 0 || $('#cb_right_image').length > 0) {
        cbox_opts.opacity='0.8';
        side_imgs = true;
    }
});

$(document).bind('cbox_complete', function() {
    if(typeof(is_ie6) != "undefined") return false;

    if($('#cb_left_image').length > 0 && $('#cb_limg').length < 1) {
        $('#colorbox').before($('#cb_left_image').clone().attr('id', 'cb_limg').css('top', $('#colorbox').css('top')));
        //$('img#cb_limg').css('top', $('#colorbox').css('top'));
    }
    if($('#cb_right_image').length > 0 && $('#cb_rimg').length < 1) {
        $('#colorbox').before($('#cb_right_image').clone().attr('id', 'cb_rimg').css('top', $('#colorbox').css('top')));
        //$('img#cb_rimg').css('top', $('#colorbox').css('top'));
    }
    /*
    if(side_imgs == true && typeof(is_ie6) != "undefined") {
        //$('#cb_limg, #cb_rimg').css({ height:'700px', width:'459px', display:'block' });
        $('img#cb_limg, img#cb_rimg').css({ display:'block' });
        $(document).pngFix();
    }
    */
});

$(document).bind('cbox_closed', function() {
    $('#cb_limg, #cb_rimg').remove();
});
// END



