/***
	Generic JavaScript functions.
	(Comments to luckyluke@luckyluke.eu)
***/

$(document).ready(function(){
	$("#overlay_dd").hide();//this hides element that can be found in /js/4-Payment-Details.js
	$("#overlay").hide();
	$(".tabContent").hide();
	if($(".tabs")[0]){
		$.jtabber({
			mainLinkTag: ".tabs a", // much like a css selector, you must have a 'title' attribute that links to the div id name
			activeLinkClass: "on", // class that is applied to the tab once it's clicked
			hiddenContentClass: "tabContent", // the class of the content you are hiding until the tab is clicked
			showDefaultTab: 1, // 1 will open the first tab, 2 will open the second etc.  null will open nothing by default
			showErrors: false, // true/false - if you want errors to be alerted to you
			effect: 'fade', // null, 'slide' or 'fade' - do you want your content to fade in or slide in?
			effectSpeed: 'medium' // 'slow', 'medium' or 'fast' - the speed of the effect
		})
	}
	
	$(".collapsible H3 SPAN").wrap("<a href=\"#\"></a>")
	$(".collapsible H3").next().hide()
	$(".collapsible H3").click(function(){
		$(this).toggleClass("expanded")
		if($(this).next().css("display")!="block"){
			$(this).next().slideDown(250);
		} else {
			$(this).next().slideUp(250);
		}
		return false;
	})
	overlayInitialized = false;
	$("#checkTheAnswers").click(function(){
		targetUrl = document.forms[0].action;
		$("#canvas").css({opacity:"0.3"});
		$("#footer").css({opacity:"0.3"});

		$("#overlay").appendTo("body")

		$("#overlay").css({position:"absolute",zIndex:"500",background:"#FFFFFF",border:"1px solid #CCCCCC",padding:"10px 15px 10px 15px",width:"350px"})
		myLeft = parseInt((document.body.offsetWidth-$("#overlay").width())/2);
		myTop = parseInt((document.body.offsetHeight-$("#overlay").height())/3);
		$("#overlay").css({left:myLeft,top:myTop})
		if (!overlayInitialized){
			$("#overlay").prepend("<p class=\"tar\" style=\"margin-top:0px;\"><a href=\"javascript:closeMe();\">Close</a></p>")
			$("#overlay").append("<p class=\"tac\" style=\"margin-top:20px;\"><a href=\""+targetUrl+"\"><img src=\"img/buttons/continue.gif\" width=\"80\" height=\"21\" alt=\"Continue\" title=\"Continue\"></a></p>")
			overlayInitialized = true;
		}
		$("#overlay").show();
		return false;
	})
	$(".tTip").mouseover(function(event){
		if($(".toolTip")[0]==null || $(".toolTip")[0]=="undefined"){
			$("body").append("<div class=\"toolTip\"><img class=\"wedge\" src=\"img/bg/wedge.gif\" width=\"11\" height=\"22\" alt=\"\" /><p id=\"ttCnt\"></p></div>");
		}
//		$(".toolTip").css({left:event.pageX,top:event.pageY})
		$(".toolTip").css({left:findPosX($(this)[0])+35,top:findPosY($(this)[0])-10})
//		alert($(".toolTip").html());
		oDescDiv = document.getElementById( $(this).attr("id") + '_desc' );
		theTitle = oDescDiv.innerHTML;
		$("#ttCnt").html(theTitle);
		$(".toolTip").show()
	})
	$(".tTip").mouseout(function(event){
		$(".toolTip").hide()
	})
})
function closeMe(){
	var oIframeContainerDiv = document.getElementById( 'iframeContainerDiv' );
	
	$("#canvas").css({opacity:"1"});
	$("#footer").css({opacity:"1"});
	$("#overlay").hide();
	
	$("#overlay_dd").hide();
	oIframeContainerDiv.innerHTML = '';
	
}
function findPosY(obj){
	var curtop = 0;
//	if (opr){ curtop = parseInt((document.body.offsetHeight)); }
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) curtop += obj.y;
	return curtop;
}
function findPosX(obj){
	var curleft = 0;
//	if (opr){ curleft = parseInt((document.body.offsetWidth)); }
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}
