addLoadEvent(checkSelectedTab);
//addLoadEvent(positionFooter);

function checkSelectedTab(){
	var wysiwygTab = document.getElementById('wysiwyg-tab');
	var textTab = document.getElementById('text-tab');
	var previewTab = document.getElementById('preview-tab');
	var dropshadowElement = document.getElementById('jive-markup-overlay');
	
	if(wysiwygTab != null || textTab != null || previewTab != null){
		if(wysiwygTab.className == 'current' || previewTab.className == 'current'){
			dropshadowElement.style.background = '#fff';
			if(BrowserDetect.browser == 'Explorer'){
				dropshadowElement.style.filter = 'alpha(opacity=40)';	
			} else {
				dropshadowElement.style.opacity = '.4';
			}
		} else if(textTab.className == 'current'){
			dropshadowElement.style.background = 'none';
			if(BrowserDetect.browser == 'Explorer'){
				dropshadowElement.style.filter = 'alpha(opacity=100)';	
			} else {
				dropshadowElement.style.opacity = '1';
			}
		} else {
			dropshadowElement.style.background = 'none';
			dropshadowElement.style.opacity = '1';
		}
	}
}

function togglePlainTextOverlay(elementID){
	var liElement = document.getElementById(elementID);
	var dropshadowElement = document.getElementById('jive-markup-overlay');
	
	if(elementID == 'text-tab'){
		dropshadowElement.style.background = 'none';
		if(BrowserDetect.browser == 'Explorer'){
			dropshadowElement.style.filter = 'alpha(opacity=100)';	
		} else {
			dropshadowElement.style.opacity = '1';
		}
	} else {
		dropshadowElement.style.background = '#fff';
		if(BrowserDetect.browser == 'Explorer'){
			dropshadowElement.style.filter = 'alpha(opacity=40)';
		} else {
			dropshadowElement.style.opacity = '.4';
		}
	}
	
}

function positionFooter(){
	var footerbar = document.getElementById('footerbar');
	var body = document.getElementsByTagName('body');
	
	// get dimensions of the page
	var pageSizes = getPageSizeWithScroll();
	
	// don't position the footer in IE 6.
	if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7){
		return false;
	} else {
		if(pageSizes[1] == document.body.clientHeight){
			footerbar.style.float = 'none';
			footerbar.style.display = 'block';
			footerbar.style.position = 'absolute';
			footerbar.style.bottom = 0;
			footerbar.style.left = 0;
		}
	}
}

function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}

/*
 * Function to add onload events while preserving existing onload events
 * @param func - sting
 * 	function name
 */
 function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


/* jQuery Code --------------*/
/*---------------------------*/
$(document).ready(function(){
	
	//The bullet point expander and collapser
	$("ul.blackbullet li a.trigger").click(function(){
		var linkElement = $($(this));
		var divElement = $($(this).siblings());
		
		linkElement.toggleClass('open');
		divElement.slideToggle(400);
	});
	
	//External bullet point expanders.
	$("a.licensetrigger").click(function(){
		var linkElement = $($("a#license"));
		var divElement = $($("a#license").siblings());
		
		linkElement.toggleClass('open');
		divElement.slideToggle(400);
	});
	
	//Hiding and showing the right content in the news list depending on selected tab.
	$("div.news").ready(function(){
		//Get Selected tab
		var selectedTab = $($("li.selected"));
		var selection = selectedTab.children().attr("class");

		$("ul.newslist").each(function(i){
			
			//Show the right set of li links
			if($(this).attr("class") == "newslist "+selection){
				$(this).css("display","block");
			} else {
				$(this).css("display","none");
			}
			
		});
	});
	
	//Switching the selected tab for the news list
	$("div.newsnav ul li a").click(function(){
		var selection = $(this).attr("class");
		
		$("ul.newslist").each(function(i){
			//Show the right set of li links
			if($(this).attr("class") == "newslist "+selection){
				$(this).css("display","block");
			} else {
				$(this).css("display","none");
			}
		});
		
		$("div.newsnav ul").children().each(function(i){
			//Highlight right tab
			if($(this).children().attr("class") == selection){
				$(this).addClass("selected");
			} else {
				$(this).removeClass("selected");
			}
		});
		
	});
	
	$("div#videothumbs ul li a.thumbnail").append('<span class="play-arrow"></span>');
});

