function setTopBgImagePosition(){
	var window_width;
	if(window.innerWidth){
		window_width=window.innerWidth;
	}else if(window.offsetWidth){
		window_width=window.offsetWidth;
	}else if(document.body.clientWidth){
		window_width=document.body.clientWidth;
	}else if(document.documentElement && document.documentElement.clientWidth){
		window_width=document.documentElement.clientWidth;
	}
	
	var diff=(window_width-document.getElementById("top_inner0").offsetWidth)/2;
	var xoffset=10+diff-266;
	document.getElementById("outer_top_wrapper").style.backgroundPosition=xoffset+"px 0px";
}

function disableSomeStylesWhenJavascript(){
	var selector="";
	var i=-1;
	var rules;
	
	if(document.styleSheets[0])
		if(document.styleSheets[0].cssRules){
			rules=document.styleSheets[0].cssRules;
		}else if (document.styleSheets[0].rules){
			//http://msdn2.microsoft.com/en-us/library/ms530711.aspx#User_Defined_Style_S
			rules=document.styleSheets[0].rules;
		}
		
	if(rules){
		while(selector!="#outer_top_wrapper"){
			selector=rules[++i].selectorText;
		}
		rules[i].style.backgroundPosition="";
	}
}

disableSomeStylesWhenJavascript();

window.onresize=setTopBgImagePosition;
window.onload=function(){
	window.onresize();
	//http://developer.mozilla.org/en/docs/DOM:stylesheet.cssRules

	$("#left>ul>li.opener").each(function(){
		$(this).children("a").click(function(){	
			if($(this).parent().get(0).isOpen && !$(this).parent().get(0).className.match(/active/i)){
				$(this).parent().removeClass("opened");
				$(this).parent().get(0).isOpen=false;
				if(this.blur) this.blur();
			}
			else if($(this).parent().children("ul").length>0){
				$(this).attr({href:"javascript:void(null)"});
				$(this).parent().addClass("opened");
				$(this).parent().get(0).isOpen=true;
				if(this.blur) this.blur();
			}
		});
	});
	
	$("a.background-link").each(function(){
		$(this).click(function(){
			var href=this.href;
			open2(href, 2);
			return false;
		});
	});
		
	$("#content p.toggler").each(function(){
			$(this).next().css("display","none");
			$(this).click(function(){
				if($(this).next().css("display")=="block"){
					$(this).next().css("display","none");
				}else{
					$(this).next().css("display","block");
				}
			});
			$(this).mouseover(function(){
				$(this).css("text-decoration","underline");
			});
			$(this).mouseout(function(){
				$(this).css("text-decoration","none");
			});
	});

	$("#content form.validation-required").each(function(){
			$(this).validationAideEnable(null, {
				showSummary:false,
				showInlineMessages:true,
				inlineShowSpeed:"fast",
				summaryMessage:
										,
				summaryFieldMessageFormat: "##FIELD##"
				});
	});
	
	//alert($("#content a").index($("a.jqModal")[0]));
	if($("#content a.jqModal")[0]){
		$("#content").append("<div class=\"jqmWindow\" id=\"jqDialog\"></div>");
		var big_image_href=$($("#content a.jqModal")[0]).attr("href");
		$("#jqDialog").append("<img/>");

		;

		var f_each=function(){
			$(this).attr("src",big_image_href);
			$(this).attr("alt",alt_text);
		}
		$("#jqDialog img").each(f_each);
		$("#jqDialog").append("<a href=\"#\" class=\"jqmClose\">"+close_text+"</a>");
		$('#jqDialog').jqm();
	};
	//$("#content.jqModal
//$("p").append("<b>Hello</b>");
}

//TODO: place in separate lib
//http://snippets.dzone.com/posts/show/2915
function open2(url, opt){
  if (opt == 0) // current window
    window.location = url;
  else if (opt == 1) // new window
    window.open(url);
  else if (opt == 2) // background window
    {window.open(url); self.focus();}
}

