$.smPrepareCSS = function(){

	$("#d_main_header ul li a").css("padding","0px").wrapInner("<div class='center'></div>").prepend("<div class='left'>&nbsp;</div>").append("<div class='right'>&nbsp;</div>");
	$(".d_center").prepend("<div class='top'></div>");

	jQuery.easing.def = 'easeInOutBounce';
	$(".d_left .accordion").each(function(){
		var p = location.hash.slice(1).split(":");
		var a = ":first-child";
		if(p[0]=="accordion" && $(this).find("#" + p[1]).size()>0)
			a = "#" + p[1];
		else if($(this).find(".active").size()>0)
			a = ".active";

		this._accordion = $(this).accordion({
			active: a,
		        header: 'h6'
		});
	});

	$(".d_center .accordion").each(function(){
		var p = location.hash.slice(1).split(":");
		var a = ":first-child";
		if(p[0]=="accordion" && $(this).find("#" + p[1]).size()>0)
			a = "#" + p[1];
		else if($(this).find(".active").size()>0)
			a = ".active";

		this._accordion = $(this).accordion({
			active: a,
		        header: 'h2'
		});

	});
	$(".d_center .accordion h2").hover(function(){
		$(this).addClass("hover");
	}, function(){
		$(this).removeClass("hover");
	});

	$.datepicker.setDefaults({
		firstDay: 1,
		yearRange: '1908:2008',
		dateFormat: 'yy-mm-dd',
		appendText: '&nbsp;(yyyy-mm-dd)',
		showAnim: 'fadeIn'
	});
	$("input.date").attachDatepicker();
};

$("document").ready(function(){
	var hash = location.hash.slice(1);
	if(hash)
	{
		var hashElement = document.getElementById(hash);
		$(hashElement).addClass("active");
	}
	$.smPrepareCSS();
})
var hash = location.hash.slice(1);
setInterval(function(){
	var thash = location.hash.slice(1);
	if(hash != thash)
	{
		hash = thash;
		var c = hash.split(":")[0];
		if(c=="accordion")
		{
			var i = hash.split(":")[1];
			$("#"+i).each(function(){
				if(this.parentElement._accordion) this.parentElement._accordion.activate(this);
			});
		}
	}
}, 250);


var mainContentsHeight = 0;

function initComponents() {
	mainContentsHeight = document.getElementById("d_main_contents").offsetHeight;
	document.getElementById("d_center").style.height = (mainContentsHeight - 144) + "px";
}

function resizeComponents() {
	fHeight = pageHeight() - mainContentsHeight - 18;


	if (windowHeight() < (mainContentsHeight + 145.0 + 18)) {
		document.getElementById("d_main_footer").style.height = "145px";
	} else {
		if (fHeight > 145) {
			fHeight = fHeight - (pageHeight() - windowHeight());
			document.getElementById("d_main_footer").style.height = fHeight + "px";
		} else {
			document.getElementById("d_main_footer").style.height = "145px";
		}
	}
}

function windowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function pageHeight()
{
	var docHeight;
	if (typeof document.height != 'undefined') {
		docHeight = document.height;
	}
	else if (document.compatMode && document.compatMode != 'BackCompat') {
		docHeight = document.documentElement.scrollHeight;
	}
	else if (document.body && typeof document.body.scrollHeight != 'undefined') {
		docHeight = document.body.scrollHeight;
	}
	return docHeight;
}
