//common javascript functions

function usedSlider() {
	featuredcontentslider.init({
		id: "slider1", //id of main slider DIV
		contentsource: ["inline", ""], //Valid values: ["inline", ""] or ["ajax", "path_to_file"]
		toc: "#increment", //Valid values: "#increment", "markup", ["label1", "label2", etc]
		nextprev: ["", "Next"], //labels for "prev" and "next" links. Set to "" to hide.
		enablefade: [true, 0.05], //[true/false, fadedegree]
		autorotate: [true, 3500], //[true/false, pausetime]
		onChange: function(previndex, curindex){ //event handler fired whenever script changes slide
		//previndex holds index of last slide viewed b4 current (1=1st slide, 2nd=2nd etc)
		//curindex holds index of currently shown slide (1=1st slide, 2nd=2nd etc)
		}
	});
}

function newSlider() {
	featuredcontentslider.init({
		id: "slider2", //id of main slider DIV
		contentsource: ["inline", ""], //Valid values: ["inline", ""] or ["ajax", "path_to_file"]
		toc: "#increment", //Valid values: "#increment", "markup", ["label1", "label2", etc]
		nextprev: ["", "Next"], //labels for "prev" and "next" links. Set to "" to hide.
		enablefade: [true, 0.05], //[true/false, fadedegree]
		autorotate: [true, 3500], //[true/false, pausetime]
		onChange: function(previndex, curindex){ //event handler fired whenever script changes slide
		//previndex holds index of last slide viewed b4 current (1=1st slide, 2nd=2nd etc)
		//curindex holds index of currently shown slide (1=1st slide, 2nd=2nd etc)
		}
	});
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function setButtonState(target, state) {
	var element = document.getElementById( target );
	if( element )
		element.disabled = state;
}

//ScrollToControl('elementID')
function elementPosition(obj) {
	var curleft = 0, curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return { x: curleft, y: curtop };
}
		
function ScrollToControl(id) {
	var elem = document.getElementById(id);
	var scrollPos = elementPosition(elem).y;
	scrollPos = scrollPos - document.documentElement.scrollTop;
	var remainder = scrollPos % 200;
	var repeatTimes = (scrollPos - remainder) / 200;
	ScrollSmoothly(scrollPos,repeatTimes);
	window.scrollBy(0,remainder);
}
var repeatCount = 0;
var cTimeout;
var timeoutIntervals = new Array();
var timeoutIntervalSpeed;
function ScrollSmoothly(scrollPos,repeatTimes) {
	if(repeatCount < repeatTimes) {
		window.scrollBy(0,200);
	}	else {
		repeatCount = 0;
		clearTimeout(cTimeout);
		return;
	}
	repeatCount++;
	cTimeout = setTimeout("ScrollSmoothly('" + scrollPos + "','"+ repeatTimes +"')",1);
}
//end ScrollToControl

function adminPopup() {
	window.open('login.php', 'adminWindow', 'status=0, titlebar=0, menubar=0, location=0, scrollbars=1, height=700, width=980')
}

function adminFromSub() {
	window.open('../login.php', 'adminWindow', 'status=0, titlebar=0, menubar=0, location=0, scrollbars=1, height=700, width=980')
}

//bookmark
function bookmarkpage(url, title) {
	// user agent sniffing is bad in general, but this is one of the times 
	// when it's really necessary
	var ua=navigator.userAgent.toLowerCase();
	var isKonq=(ua.indexOf('konqueror')!=-1);
	var isSafari=(ua.indexOf('webkit')!=-1);
	var isMac=(ua.indexOf('mac')!=-1);
	var buttonStr=isMac?'Command/Cmd':'CTRL';

	if(window.external && (!document.createTextNode ||
		(typeof(window.external.AddFavorite)=='unknown'))) {
			// IE4/Win generates an error when you
			// execute "typeof(window.external.AddFavorite)"
			// In IE7 the page must be from a web server, not directly from a local 
			// file system, otherwise, you will get a permission denied error.
			window.external.AddFavorite(url, title); // IE/Win
	} else if(isKonq) {
		alert('You need to press CTRL + B to bookmark our site.');
	} else if(window.opera) {
		void(0); // do nothing here (Opera 7+)
	} else if(window.home || isSafari) { // Firefox, Netscape, Safari, iCab
		alert('You need to press '+buttonStr+' + D to bookmark our site.');
	} else if(!window.print || isMac) { // IE5/Mac and Safari 1.0
		alert('You need to press Command/Cmd + D to bookmark our site.');    
	} else {
		alert('In order to bookmark this site you need to do so manually '+
			'through your browser.');
	}
}

