var pageLoaded = 0;
var searchbox;
var nav;
var nav_content;
var subscribeForm;
var email_txtBox;
var blogname;
var postBody;
var currwidth;
var getlist;
var categoryList;
var category_content;
var widget;
var widget_content;
var navBody;

window.onload = function() {
	pageLoaded = 1;
}

function loader(i,f) {
	var j;
	if (document.getElementById && document.getElementById(i) != null)
		{
			j = document.getElementById(i);
			f(j);
		}
	else if (!pageLoaded) setTimeout('loader(\''+i+'\','+f+')',100);
}

function change_searchtext(searchbox) {
	if(BrowserDetect.browser == 'Explorer') {
			searchbox.style.height = '33px';
			
	}
	
	if(searchbox.value == '') {
			searchbox.value = 'Enter your keyword here';
			searchbox.style.color = '#a5a7a8';
	}
		
	else if(searchbox.value != '' || searchbox.value != 'Enter your keyword here') {
		searchbox.style.color = '#000000';
	}
	
	function chkSpaces() {
		var rmvSpaces = new Array();
		rmvSpaces = searchbox.value.split(' ');
		for(i=0; i<=rmvSpaces.length-1; i++) {
			if(rmvSpaces[i] == '') {
				if(i == rmvSpaces.length-1) {
					return true;
				}
				continue;
			}
			else return false
		}
	}

	document.searchform.onsubmit = function() {
		if(searchbox.value == 'Enter your keyword here' || chkSpaces()) {
			alert('Please enter a keyword to search');
			searchbox.value = '';
			searchbox.focus();
			searchbox.style.color = '#000000';
			return false
		}
		else return true
	}

	searchbox.onfocus = function() {
		if(searchbox.value == 'Enter your keyword here') {
			searchbox.value = '';
			searchbox.style.color = '#000000';
		}
	}
	searchbox.onblur = function() {
		if(searchbox.value == '') {
			searchbox.value = 'Enter your keyword here';
			searchbox.style.color = '#a5a7a8';
		}
		else if(searchbox.value != '' || searchbox.value != 'Enter your keyword here') {
			searchbox.style.color = '#000000';
		}
	}
}

function get_nav(nav) {
	function display_nav(nav_content) {
	nav.innerHTML = nav_content.innerHTML;
	document.getElementById('navbtns_container').style.marginLeft = returnSize_nav();
	document.getElementById('navbtns_container').style.position = 'absolute';
	document.getElementById('navbtns_container').style.left = '50%';
	}
	
	loader('navigation_content',display_nav);
}

function get_category(categoryList) {
			function display_category(category_content) {
			categoryList.innerHTML = category_content.innerHTML;
	}
	loader('list_container',display_category);
	if(categoryList.innerHTML == '') {
		categoryList.style.display = 'none';	
	}
}

function get_widget(widget) {
	function display_widget(widget_content) {
	widget.innerHTML = widget_content.innerHTML;
	}
	
	loader('widget_content',display_widget);
}

function get_txtBox(subscribeForm) {
	function startValidate(email_txtBox) {
		subscribeForm.onsubmit = ValidateForm;
		if(BrowserDetect.browser == 'Explorer') {
			email_txtBox.style.height = '32px';
		};
	}

		loader('email_txtBox',startValidate);
}

function adjustWidth_Header(blogname) {
		width = (returnSize_Window()-367).toString() + 'px';
		blogname.style.width = width;
}
	
function adjustWidth_Postbody(postBody) {
		width = (returnSize_postbody()-345).toString() + 'px';
		postBody.style.width = width;	
}

window.onresize = function() {
	if(document.documentElement && currwidth != document.documentElement.clientWidth) {
		adjustWidth_Header(document.getElementById('blogname'));	
		adjustWidth_Postbody(document.getElementById('post_container'));
	}
	else if( typeof( window.innerWidth ) == 'number' && currwidth != window.innerWidth) {
		adjustWidth_Header(document.getElementById('blogname'));	
		adjustWidth_Postbody(document.getElementById('post_container'));
	}
	else if( document.body && currwidth != document.body.clientWidth ) {
		adjustWidth_Header(document.getElementById('blogname'));	
		adjustWidth_Postbody(document.getElementById('post_container'));
	}
	currwidth = document.documentElement.clientWidth;
}

function create_navbar(getlist) {
	var children = new Array();
	children = getlist.childNodes;
	
	var listContainer = getlist.parentNode;
	listContainer.removeChild(getlist);
	
	var putHTML='<div class=\"navbar_design\" id=\"navbar_designl\"></div>';
	for (i=0; i<children.length; i++) {
		if (children[i].innerHTML == null) {continue;}
		else { 
			putHTML += '<div class=\"navbtn\"><div><div><div><div class=\"cornertl\"><div class=\"cornertr\"><p class=\"nav_text\">' + children[i].innerHTML + '</p></div></div></div></div></div></div>';
		}
	}
	putHTML += '<div class=\"navbar_design\" id=\"navbar_designr\"></div>'
	listContainer.innerHTML = putHTML;
	
	loader('navigation',get_nav);
}


loader('categories',get_category);
loader('widget_container',get_widget);
loader('s',change_searchtext);
loader('subscribeForm',get_txtBox);
loader('blogname',adjustWidth_Header);
loader('post_container',adjustWidth_Postbody);
loader('navlist',create_navbar);