/*
 * alertBox - jQuery plugin for alert balloons
 *
 * Based on Tooltip plug-in by Jörn Zaefferer, Stefan Petre
 * Copyright (c) 2007 Iker Tolosa. Barceloviajes.com
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Compression: xtreeme.com optimizer (shrinksafe)
 */
(function($){
var box,
tTitle,
tBody,
duration,
tID1,tID2
$.fn.alertBox=function(msg,settings){
settings=$.extend($.extend({},arguments.callee.defaults),settings ||{})
settings.message=msg
duration=settings.duration
$(this).bind("launch",handler)
.each(function(){
this.tSettings=settings
this.target=this.id
}).bind("focus",hideMe)
return this.trigger("launch",msg)}
function handler(){
var target=this.target,
settings=this.tSettings
var h,w,bordertop,borderbottom,borderimage,t
var posX,posY
if($("div").index($("#alertBox")[0])==-1){
box=$("<div id='alertBox'><div id='alertBoxContent'><h4></h4><p class='body'>"+settings.message+"</p></div><div id='alertBoxArrow'></div></div>")
box.hide()
.css({position: "absolute",zIndex: 3000})
.appendTo("body")
tTitle=$("h4",box)
tBody=$("p:eq(0)",box)
}else{
box.hide()
tBody.html(settings.message)}
var el=$("#"+target)
var o={}
o=el.offset()
switch(settings.boxWidth){
case "big":
w=477
break
case "normal":
w=293
break
case "lite":
default:
w=193
break}
switch(settings.position){
case 'right':
bordertop="1px"
borderbottom="1px"
borderimage=""
posX=o.left+o.scrollLeft+el.width()+5
posY=o.top+o.scrollTop-2
t=1
break
case 'top':
bordertop="1px"
borderbottom="0px"
borderimage="url("+settings.imgpath+"bottomArrow.gif) top left no-repeat"
posX=o.left+o.scrollLeft+10
posY=o.top+o.scrollTop-box.height()+3
$("#alertBoxContent").after($("#alertBoxArrow"))
t=0
break
case 'bottom':
default:
bordertop="0px"
borderbottom="1px"
borderimage="url("+settings.imgpath+"topArrow.gif) top left no-repeat"
posX=o.left+o.scrollLeft+10
posY=o.top+o.scrollTop+el.height()-0
$("#alertBoxContent").before($("#alertBoxArrow"))
t=9
break}
$("#alertBoxContent").css("border-top-width",bordertop)
$("#alertBoxContent").css("border-bottom-width",borderbottom)
$("#alertBoxContent").css("width",w)
$("#alertBoxArrow").css("background",borderimage)
$("#alertBoxArrow").width(w+1)
if($.browser.msie){
$("#alertBoxContent").bgiframe({opacity:false,left:1,top:t,width:w})
$(".bgiframe").css({top:t,width:w})}
box.css({left: posX+"px",top: posY+"px"})
if(settings.delay>0){
clearTimeout(tID1)
tID1=setTimeout(showMe,settings.delay)
}else{
showMe()}
return box}
function showMe(){
box.fadeIn("normal",wait())}
function wait(){
clearTimeout(tID2)
tID2=setTimeout(hideMe,duration)}
function hideMe(){
if(box.css("opacity")>0.9&&box.css("display")=="block"){
box.fadeOut("slow",function(){
$(this).unbind("launch")
clearTimeout(tID2)
})}}
$.fn.alertBox.defaults={
delay: 0,
position: "bottom",
boxWidth: "lite",
duration: 3500,
imgpath: "/jsgen/imgs/alertbox/",
showBody: null}
})(jQuery)
function alertbox(msg,id){
$("#"+id).alertBox(msg)}
