var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
var headline_running = 0;
var hc = 0;


function headline_rotate() {

	headline_running = 1;
	current_headline = (old_headline + 1) % headline_count;

	$("div.headline:eq(" + old_headline + ")").animate({top: -276},"slow", function() {
		$(this).css('top', '276px');
	});
	$("div.headline:eq(" + current_headline + ")").animate({top: 5},"slow");
	
	old_headline = current_headline;
} 


function openLinkJQ(getFile, destination,formName){

	$.get(getFile,
	{},
	function(data){
		$("#" + destination).html(data);
	}
	);
}

var xmlhttp = false;

function createXmlHttp(){
	if(window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
		if(xmlhttp.overrideMimeType){
			xmlhttp.overrideMimeType('text/xml');
		}
	} else if(window.ActiveXObject){
		try{
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
			}
		}
	}
	
	if(!xmlhttp) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
}


function openLink(url,divTag) {
	dynamicUnload();
		
	createXmlHttp();
	
	xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState==4) {
		document.getElementById(divTag).innerHTML = xmlhttp.responseText;
		
			getDeps();
		}
	}

	xmlhttp.open('GET',url,true);
	xmlhttp.send(null);

	
}

function openLinkPost(url,divTag,formData) {	

	dynamicUnload();
		
	createXmlHttp();

	xmlhttp.open('POST', url, true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
	        document.getElementById(divTag).innerHTML = xmlhttp.responseText;
	        
	        	getDeps();
	        }
	    }
	xmlhttp.send(getquerystring(formData));
}

function getquerystring(formData) {

    var formElement = formData.split(","); 
    var len=formElement.length;
    var ajxPostData = 'ajxPost=ok';
    
    for(var i=0; i<len; i++) 
    {
    	ajxPostData += '&' + formElement[i] + '=' + encodeURIComponent(document.getElementById(formElement[i]).value);  
    	
    }
    	
    return ajxPostData;
}

function dynamicUnload(){
	var i = 0;
	while(i < 1){
		if(document.getElementById("dynl")){
			document.getElementsByTagName('head')[0].removeChild(document.getElementById("dynl"));
		}else{
			i++;
		}
		
	}
}

function getDeps(){
	
	if(document.getElementById('deps')){
		 var deps = document.getElementById('deps').innerHTML.split(";");
		 for(var i=0; i<deps.length; i++) 
	    {
			 var dynType = deps[i].substr(deps[i].length-3,3);
			 if(dynType == 'css'){
				 load_css(deps[i]);
			 }else{
			 //if(dynType == '.js'){
				 load_js(deps[i]);
			 }
	    }
	}
}

function load_js(jScript){
	script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = jScript;
	script.id = 'dynl';
	document.getElementsByTagName('head')[0].appendChild(script);
}

function load_css(cScript){
	lnk = document.createElement('link');
	lnk.type = 'text/css';
	lnk.href = cScript;
	lnk.rel = 'stylesheet';
	lnk.id = 'dynl'
	document.getElementsByTagName('head')[0].appendChild(lnk); 
}
