$(document).ready(function() {	
	loadCSS();
});

function createCookie(c_name, value, exdays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value = escape(value)
			+ ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
	document.cookie = c_name + "=" + c_value;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function loadcssfile(filename,relativePath){
	  var relPath = '';
	  if(null != relativePath && 'undefined' != relativePath && '' != relativePath){
		  relPath = relativePath;
	  }
	  var cssPath = getCSSPath();
	  var fileref=document.createElement("link");
	  fileref.setAttribute("rel", "stylesheet");
	  fileref.setAttribute("type", "text/css");
	  fileref.setAttribute("href", relPath + cssPath + '/' + filename);
	  if (typeof fileref!="undefined"){
		  document.getElementsByTagName("head")[0].appendChild(fileref);
	  }
}
function loadTournamentFlyer(){

	  var fileref=document.createElement("img");
	  fileref.setAttribute("id", "background");
	  fileref.setAttribute("src", "/images/njttcbackground.jpg");
         fileref.setAttribute("style", "width:100%; height:100%; position:absolute; z-index:-1; top:0; left:0;");
	  if (typeof fileref!="undefined"){
		  document.getElementsByTagName("body")[0].appendChild(fileref);
	  }

}
var siteRoot = '';
function loadCSS(){
	var fullPath = window.location.pathname;
	fullPath = fullPath.replace(/^.*\\/, '');
	var start = fullPath.indexOf(siteRoot);
	if(-1 != start){
		var relevantPath = fullPath.slice(start+siteRoot.length);
		var tokens = relevantPath.split("/");
		var rootDir = tokens[1];
		switch(rootDir){
			case '':
			case 'index.html':{
				loadIndexCSS();
			}
			break;
			case 'cgi-bin':{
				var fileName = tokens[2];
				if(null != fileName && 'undefined' != fileName && '' != fileName){
					if(fileName.indexOf('monday_regform') === 0 ){
						loadMondayRegFormCSS();						
					}else if(fileName.indexOf('regform') === 0){
						loadMondayRegFormCSS();
					}else{
						loadMondayRegFormCSS();
					}			
				}
			}
			break;
			case 'pis':{
				var fileName = tokens[2];
				if(null != fileName && 'undefined' != fileName && '' != fileName){
					if(fileName == 'equipment.html'){
						loadEquipCSS();
					}else if(fileName == 'training.html'){
						loadTrainingCSS();		
					}else if(fileName.indexOf('news') === 0){
						loadPISNEWSCSS();
						loadInnerPagesCSS('../');
					}else if(fileName == 'Tournaments.html'){												
						loadTournamentCSS();
						loadInnerPagesCSS('../');
					}else{
						loadInnerPagesCSS('../');
					}
				}
			}
			break;
			case 'tournament':{
				var fileName = tokens[2];
				if(null != fileName && 'undefined' != fileName && '' != fileName){
					if(fileName.indexOf('register_') === 0 ){
						loadTournamentRegisterCSS();						
					}else if(fileName.indexOf('registration') === 0){
						loadcssfile('volunteer.css','../');
						loadTournamentRegisterCSS();						
					}else if(fileName.indexOf('results_') === 0){
						loadTournamentResultsCSS();						
					}else if(fileName.indexOf('roster_') === 0){
						loadTournamentRosterCSS();						
					}else if(fileName.indexOf('volunteer') === 0){
						loadTournamentVolunteerCSS();						
					}else if(fileName.indexOf('faq') === 0){
						loadcssfile('faq.css','../');
						loadFaqCSS();						
					}else if(fileName.indexOf('monday') === 0){
						loadcssfile('mondaytournament.css','../');
						loadTournamentCommon();
					}else{
						loadTournamentCommon();
					}					
				}
			}
			break;
			case 'NJTTCEquipment':{
				loadEquipCSS();
			}
			break;
			case 'leagues':{				
				if(null != tokens[3] && "archives" == tokens[3]){
					loadInnerPagesCSS('../../../../');
				}else{
					loadInnerPagesCSS('../../');
				}
			}
			break;
			case 'lists':{								
				loadInnerPagesCSS('../../');				
			}
			break;
			case 'Flickr':{
				if(tokens.length >= 4){
					var fileName = tokens[3];
					if(null != fileName && 'undefined' != fileName && '' != fileName){
						if(fileName == 'photo.php'){
							loadInnerPagesCSS('../../');
						}
					}
				}				
			}
			break;
		}
	}
       //loadTournamentFlyer();
}
var schemaCookieName = 'activeSkinSchema';
function writeSkinName(skinName){
	// Create (or update) the value of a cookie:
	createCookie(schemaCookieName, skinName,180);
}
function getDefaultSkinName(){
	return 'dodgerBlue';
}
function getSkinName(){
	var skinName;
	// Create (or update) the value of a cookie:
	skinName = readCookie(schemaCookieName);
	if(null == skinName || 'undefined' == skinName || '' == skinName){
		skinName = getDefaultSkinName();
	}
	return skinName;
}
function getCSSPath(){
	var cssPathName = 'css';
	var skinType = getSkinName();
	switch(skinType){
		case 'dodgerBlue':{
			
		}
		break;
		default:{
			cssPathName = cssPathName + skinType;
		}
		break;			
	}
	return cssPathName;
}
function loadIndexCSS(){
	loadcssfile('SpryMenuBarVertical.css');
	loadcssfile('innerpages.css');
	loadcssfile('njttc.css');
	loadcssfile('ticker.css');
	loadcssfile('slidediv.css');
	loadcssfile('slinkyslider.css');
	loadcssfile('equipslidediv.css');
	loadcssfile('equipment.css');
	loadcssfile('tabber.css');
}
function loadEquipCSS(){
	loadcssfile('SpryMenuBarVertical.css','../');
	loadcssfile('equipment.css','../');
	loadcssfile('njttc.css','../');
}
function loadTrainingCSS(){
	loadcssfile('SpryMenuBarVertical.css','../');
	loadcssfile('njttc.css','../');
	loadcssfile('training.css','../');
}
function loadPISNEWSCSS(){
	loadcssfile('njttc_news.css','../');
}
function loadInnerPagesCSS(relativePath){
	loadcssfile('SpryMenuBarVertical.css',relativePath);
	loadcssfile('innerpages.css',relativePath);
	loadcssfile('njttc.css',relativePath);
}
function loadTournamentResultsCSS(){
	loadcssfile('njttc_tournament.css','../');
	loadTournamentCommon();
}
function loadTournamentRegisterCSS(){
	loadcssfile('regform.css','../');
	loadcssfile('innerpages.css','../');
	loadTournamentCommon();
}
function loadTournamentRosterCSS(){
	loadcssfile('tournament_roster.css','../');
	loadTournamentCommon();
}
function loadTournamentVolunteerCSS(){
	loadcssfile('volunteer.css','../');
	loadcssfile('volform.css','../');
	loadTournamentCommon();
}
function loadFaqCSS(){
	loadcssfile('faq.css','../');
	loadcssfile('innerpages.css','../');
	loadTournamentCommon();	
}
function loadTournamentCommon(){
	loadcssfile('SpryMenuBarVertical.css','../');
	loadcssfile('njttc.css','../');
}
function loadTournamentCSS(){
	loadcssfile('njttc_tournament.css','../');
}
function loadMondayRegFormCSS(){
	loadcssfile('regform.css','../');
	loadcssfile('njttc.css','../');
       loadcssfile('SpryMenuBarVertical.css','../');
}
