var iDOMLoaded = false;
var ni1, ni2;
jQuery(document).ready(function() {
	iDOMLoaded = true;
	setTimeout("init()", 100);

if ($(".head2 a:not(.small)")[0]) {
    $("#.head2 a:not(.small)").append('<img src="/files/images/h2_arrow.gif">');

    $(".head2 a:not(.small)").hover(
			function() {
			    $(this).queue("fx", []);
			    $(this).children("img").animate({ marginLeft: "20px" }, 200);
			},
			function() {
			    $(this).parent().queue("fx", []);
			    $(this).children("img").animate({ marginLeft: "10px" }, 200);
			}
	);
}
	
/* Buble popup in form */
if ($("#content .deposits .help_buble .icon")[0]) {
	$("#content .deposits .help_buble").hover(
		function() {
			$(this).children(".buble").css("display", "block");
			var r = getAbsolutePos(this);
			var newtop = 0;
			var newleft = 0;
			if (window.XMLHttpRequest) {
				newtop = r.y - $(this).children(".buble").attr("offsetHeight") + 16;
				newleft = r.x - 288;
			} else {
				newtop = 0 - $(this).children(".buble").attr("offsetHeight") + 45;
				newleft = 0 - 285;
			}
			$(this).children(".buble").css("top", newtop + "px");
			$(this).children(".buble").css("left", newleft + "px");
		},
		function() {
			$(this).children(".buble").css("display", "none");
		}
	);
}


/* Accordeon on deposit select page */
if ($("#content .deposits > li > a")[0]) {
    $("#content .deposits > li > a").click(function() {
        if (this.parentNode.parentNode.className == "deposits" && $(this).siblings("fieldset:hidden")[0]) {
            $(this).parent().siblings().attr("className", "");
            $(this).parent().attr("className", "select");
            $("#content .deposits li fieldset:visible").slideUp("slow");
            $(this).siblings("fieldset").slideDown("slow");
        }
        return false;
    });
}

/* Content rows hover */
if ($("#content table tr")[0]) {
    $("#content table:not(.nohover) tr:not(.nohover)").hover(
		function() {
		    $(this).addClass("hover");
		},
		function() {
		    $(this).removeClass("hover");
		}
	);
}


/* Tabs on card pages */
if ($("#content ul.card_tabs")[0]) {
	if (typeof(predef_cardTabsSel) != 'undefined') {
		$("#content ul.card_tabs").tabs({ fx: { opacity: 'toggle' }, selected: predef_cardTabsSel });
	} else {
		$("#content ul.card_tabs").tabs({ fx: { opacity: 'toggle' }, selected: 0 });
	}
}
/* Tabs on card pages */
if ($("#content ul.inner_tabs")[0]) {
	$("#content ul.inner_tabs").tabs({ fx: { opacity: 'toggle' }, selected: 0 });
}

/* Filial list hover */
if ($("#content .filial_map .filial_list p")[0]) {
	$("#content .filial_map .filial_list p").hover(
		function() {
			$("#content .filial_map .filial_list p").removeClass("hover");
			$(this).addClass("hover");
			$("#content .filial_map .map img").attr("src", $(this).attr("src"));
		},
		function() {
		}
	);
}

});

function init() {
if($("#container h2 a:not(.small)")[0]) {
	$("#container h2 a:not(.small)").append('<img src="/files/images/h2_arrow.gif">');
	
	$("#container h2 a:not(.small)").hover(
			function() {
				$(this).queue("fx", []);
				$(this).children("img").animate({marginLeft: "20px"}, 200);
			},
			function() {
				$(this).parent().queue("fx", []);
				$(this).children("img").animate({marginLeft: "10px"}, 200);
			}
	);
}

/* Red content banners on index page */
if($("#content .ban input")[0]) {
	ni1 = new Image(); ni2 = new Image();
	ni1.src = 'files/images/cbb_l_over.jpg'; ni2.src = 'files/images/cbb_r_over.jpg'; 
	$("#content .ban input").hover(
		function() {
			this.className = "over";
			var pcn = this.parentNode.parentNode.className;
			$(this).parent().css("backgroundImage", "url('/files/images/cbb_"+pcn+"_over.jpg')");
		},
		function() {
			this.className = "";
			var pcn = this.parentNode.parentNode.className;
			$(this).parent().css("backgroundImage", "url('/files/images/cbb_"+pcn+".jpg')");
		}
	);
}
	
/* Vote popup show */
if($("#content input.votebut")[0]) {
	$("#content input.votebut").click(
		function() {
			if($("#votepopup").css("display") == "block" && $("#votepopup #curid").attr("value") == $(this).attr("id") ) {
				$("#votepopup").css("display", "none");
			} else {
				$("#votepopup #curid").attr("value", $(this).attr("id"));
				var pos = getAbsolutePos(this);
				$("#votepopup").css("top", pos.y + "px");
				$("#votepopup").css("left", pos.x + "px");
				$("#votepopup").css("display", "block");
			}
			return false;
		}
	);
if($("#content .vote label input")[0]) {
	$("#content .vote input.but").attr("value", $("#content .vote label input:checked").attr("value"));
	$("#content .vote label input").change(
			function() {
				$("#content .vote input.but").attr("value", $(this).attr("value"));
			}
		);
	$("#content .vote label input").focus(
			function() {
				$("#content .vote input.but").attr("value", $(this).attr("value"));
			}
		);
}
	}
	
}

function getAbsolutePos(el)
{
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent)
	{
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

function AddToFavorites(url, title) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else if (document.all) {
	window.external.AddFavorite(url, title);
	} else if (window.opera && window.print) {
		return true;
	}
}


