// JavaScript Document
/***********************************************
* DD Tab Menu II script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display]:
var initialtab=[1, "tab1"]
//Turn menu into single level image tabs (completely hides 2nd level)?
var turntosingle=0 //0 for no (default), 1 for yes
//Disable hyperlinks in 1st level tab images?
var disabletablinks=0 //0 for no (default), 1 for yes


////////Stop editting////////////////

function cascadedstyle(el, cssproperty, csspropertyNS){
	if (el.currentStyle)
		return el.currentStyle[cssproperty]
	else if (window.getComputedStyle){
		var elstyle=window.getComputedStyle(el, "")
		return elstyle.getPropertyValue(csspropertyNS)
	}
}

var previoustab=""

if (turntosingle==1)
document.write('<style type="text/css">\n#tabcontentcontainer{display: none;}\n</style>')

function expandcontent(cid, aobject){
if (disabletablinks==1)
aobject.onclick=new Function("return false")
if (document.getElementById && turntosingle==0){
highlighttab(aobject)
detectSourceindex(aobject)
if (previoustab!="")
document.getElementById(previoustab).style.display="none"
document.getElementById(cid).style.display="block"
previoustab=cid
}
}

function highlighttab(aobject){
if (typeof tabobjlinks=="undefined")
collectddimagetabs()
for (i=0; i<tabobjlinks.length; i++)
tabobjlinks[i].className=""
aobject.className="current"
}

function collectddimagetabs(){
var tabobj=document.getElementById("ddimagetabs")
tabobjlinks=tabobj.getElementsByTagName("A")
}


function detectSourceindex(aobject){
	for (i=0; i<tabobjlinks.length; i++){
		if (aobject==tabobjlinks[i]){
			tabsourceindex=i //source index of tab bar relative to other tabs
			break
		}
	}
}

function do_onload(){
	var name = window.location.pathname + window.location.search;
	var cookiename=(typeof persisttype!="undefined" && persisttype=="sitewide")? "tabcontent" : name;
	var cookiecheck=window.get_cookie && get_cookie(cookiename).indexOf("|")!=-1
	
	collectddimagetabs()

	if ( tabobjlinks[1] != null ) {	
		initTabcolor=cascadedstyle(tabobjlinks[1], "backgroundColor", "background-color")
	}
	initTabpostcolor=cascadedstyle(tabobjlinks[0], "backgroundColor", "background-color")
	
	if (typeof enablepersistence!="undefined" && enablepersistence && cookiecheck){
		var cookieparse=get_cookie(cookiename).split("|")
		var whichtab=cookieparse[0]
		var tabcontentid=cookieparse[1]
		expandcontent(tabcontentid, tabobjlinks[whichtab])
		jQuery( tabobjlinks[whichtab] ).click();
	}
	else
		expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload;

function tab(position, html, id) {
    this.position = position;
    this.html = html;
	 this.id = id;
}

function sortByPosition(a, b) {
    var x = a.position.toLowerCase();
    var y = b.position.toLowerCase();
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

function findChildTags() {
html = '';
var tabs = new Array();
var divs = document.getElementsByTagName( 'div' );
if( divs == null || divs.length == 0 ) {
alert( 'Unable to div tags' );
}


for( var i = 0; i < divs.length; i++ ) {
div = divs[i];
tabTitle = div.getAttribute( 'tabTitle' );

if( tabTitle != null && tabTitle != '' ) {
tabOrder = div.getAttribute('tabOrder');
if(tabOrder == null) tabOrder = "9";
tabs[tabs.length++] = new tab(tabOrder, ' <a onClick="expandcontent(\'' + div.getAttribute( 'id' ) + '\', this)">' + tabTitle + '</a>', div.getAttribute( 'id' ));

}
}

tabs.sort(sortByPosition);

for( var i = 0; i < tabs.length; i++ ) {
	html+= tabs[i].html;
}

document.getElementById( 'ddimagetabs' ).innerHTML = html;
initialtab=[1, tabs[0].id]  
}


function getTabbedDivContent( cid, aobject, url, divTabId ) {			

	jQuery( '#' + cid ).html( "<P>Loading....</p>" );
	
	if ( url == '' ) {

		jQuery( '#' + cid ).html( "<P>Coming Soon.</p>" );

		expandcontent( divTabId, aobject );    

	} else {
		jQuery.ajax({
		    url: url,
		    type: 'GET',
		    success: function(data){ 
	       			displayTabbedDivContent( cid, aobject, data, divTabId );
			    },
		    error: function(data) {
	   			displayErrorTabbedDivContent( cid, aobject, data, divTabId );
		    }
		});
	}
}

function displayErrorTabbedDivContent( cid, aobject, content, divTabId ) {
	jQuery( '#' + cid ).html( "<p> Unable to get the content from server.</p>" );

	expandcontent( divTabId, aobject );
}


function displayTabbedDivContent( cid, aobject, content,divTabId ) {
	jQuery( '#' + cid ).html( content );

	expandcontent( divTabId, aobject );
}



var enablepersistence=true //true to enable persistence, false to turn off (or simply remove this entire script block).
var persisttype="local" //enter "sitewide" for Tab content order to persist across site, "local" for this page only

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function savetabstate(){
	var name = window.location.pathname + window.location.search;
	var cookiename=(persisttype=="sitewide")? "tabcontent" : name
	var cookievalue=(persisttype=="sitewide")? tabsourceindex+"|"+previoustab+";path=/" : tabsourceindex+"|"+previoustab
	document.cookie=cookiename+"="+cookievalue
}

window.onunload=savetabstate
         

