var today = new Date();
var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000);
function getCookie(name) {
	var re = new RegExp(name + "=([^;]+)");
	var value = re.exec(document.cookie);
	return (value != null) ? unescape(value[1]) : null;
}
function setCookie(name, value) {
	document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
}
function a(module, action, id, msg) {
	if(typeof(msg)== 'string') {
		if (! confirm(msg)) {
			return;
		}
	}
	setCookie(module + "-" +action, id);
	var url = document.location.href;
	var re = new RegExp("^(.+?)\#?$");
	var value = re.exec(url);
	url=value[1];
	document.location.href=url;
}


function popup(url, width, height) {
	window.open(url,'livestylewin','width=' + width + ',height=' + height + ',left=300,top=300,scrollbars=yes,menubar=no,resizable=no,toolbar=no,status=no'); 
}


function showdiv(name) {
	document.getElementById(name).style['display']='block';
	document.getElementById('g1_big').style['display']='none';
}


function hidediv(name) {
	document.getElementById(name).style['display']='none';
}


var gSlideshows=new Array();

function gSlideshow(name) {

gSlideshows[name]=this;

this.name=name;
this.texts=new Array();
this.linkIds=new Array();
this.divid='';
this.linkid='';
this.playing=true;
this.countTexts=0;
this.wait=15000;
this.id=0;
this.textColor=0;
this.href='';

this.writeContent=function(text){
	eval('document.getElementById("' + this.divid + '").innerHTML=text');
}

this.createlink=function(text, lid) {
	return "<a href=\"javascript:popup('" + this.href + lid + "', '500', '300')\" id=\"" + this.linkid + "\" onmouseover=\"" + name + ".stop();\" onmouseout=\"" + name + ".con();\">" + text + "</a>";
}

this.setTexts=function(texts) {
	this.texts=texts;
	this.countTexts=this.texts.length-1;
	this.id=Math.round(Math.random()*this.countTexts);
} 

this.setLinkIds=function(idarray) {
	this.linkIds=idarray;
}

this.slide2next=function() {
	if (this.playing==true) {
		if (this.id==this.countTexts) 
			this.id=0;
		else 
			this.id++;
					
		this.writeContent(this.createlink(this.texts[this.id], this.linkIds[this.id]));
		this.textColor=219;
		this.fadein();
		setTimeout('gSlideshows["' + this.name + '"].slide2next()', this.wait);
		setTimeout('gSlideshows["' + this.name + '"].fadeout()', this.wait-1500);
	}
	
}

this.fadein=function() {
	this.textColor=this.textColor-25;
	this.changeColor(this.textColor);
	if (this.textColor>0) 
		setTimeout('gSlideshows["' + this.name + '"].fadein()', 150);
}

this.fadeout=function() {
	if (this.playing==false) return;	
	this.textColor=this.textColor+25;
	this.changeColor(this.textColor);
	if (this.textColor<219) 
		setTimeout('gSlideshows["' + this.name + '"].fadeout()', 150);
}

this.changeColor=function(c) {
	eval('document.getElementById("' + this.linkid + '").style[\'color\']="rgb(' +  c + ',' + c + ',' + c + ')"');
}

this.play=function() {
	this.playing=true;
	this.slide2next();
}

this.stop=function() {
	this.playing=false;
}

this.con=function() {
	if (this.playing==false)
		this.playing=true;
}

}





function live_goToURL() { 
  var i, args=live_goToURL.arguments; document.live_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


function close_div(name, value) {
	document.cookie=name + "=" + escape(value) + "; path=/";
}


function setNav(name, value) {
	document.cookie=name + "=" + escape(value) + "; path=/";
}

function setOpenClose(name, value) {
	document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=/";
}


function setPos(name, value) {
	document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=/";
}






var tabs=new Array();
function getTabKey(id) {
	var re = new RegExp("^.+_([^_]+)_a$");
	var value = re.exec(id);
	return value[1]
}
function getTabName(id) {
	var re = new RegExp("^(.+)_[^_]+_a$");
	var value = re.exec(id);
	return value[1]
}

function selectTab(what) {
	var id=getTabKey(what.id);
	var name=getTabName(what.id);
	oldTab=tabs[name]['active'];
	if (oldTab==id) return false;
	var el=document.getElementById (name+'_'+id+'_d');
	el.className=el.className=="tabactive"?"tabinactive":"tabactive";
	var old_el=document.getElementById (name+'_'+oldTab+'_d');
	old_el.className="tabinactive";
	var old_link=document.getElementById (name+'_'+oldTab+'_a');
	old_link.className="";
	var old_link=document.getElementById (name+'_'+id+'_a');
	old_link.className="active";
	
	tabs[name]['active']=id;
	return true;
}

$(document).ready(function() {
  $('#login').load('/templates/login.inc.php');
});

$(document).ready(function() {
	$("#pressbutton").live("click",function(){
				$('#presscontent').html('<center style="padding:50px;"><img src="/js/loader-big.gif" border="0" alt="loading..." /></center>');											
				$('#presscontent').slideDown('slow');
				setTimeout("($('#presscontent').load('/ajax/topslider.php'))",1250);
	})
});


$(document).ready(function() {
	$('#searchtab1').addClass('activetab');
	$('#searchtab2').removeClass('activetab');
	$("#searchfield").keyup(function() {
		$('#searchtab1').addClass('activetab');
		$('#searchtab2').removeClass('activetab');
		if($("#searchfield").val().length > 3) {
			$('#autocompletecontent').html('<div style="background:#B32024;"><center><img src="/js/loader-big-white.gif" border="0" /></center></div>');
			$('.searchlocimg').attr('src','/js/searchloader.gif');
			$.ajax({
					type: "GET",
					cache: true,
					url: "/ajax/autocomplete.php",
					data: {
							lang: language,
							q: $("#searchfield").val()
					   },
					success: function(data){
						if(data!="") {
						$('#searchresults').show();
						$('#autocompletecontent').html(data);
						}
					}
			});	
		};
		
	});
	
	$("#searchresults").mouseleave(function() {
		$(this).hide();
	});	
	
});

function changeTab(id) {
		$('#searchtab'+id).addClass('activetab');
		$('.searchtab').not('#searchtab'+id).removeClass('activetab');
		$('#autocompletecontent').html('<div style="background:#B32024;"><center><img src="/js/loader-big-white.gif" border="0" /></center></div>');
				$.ajax({
					type: "GET",
					cache: true,
					url: "/ajax/autocomplete.php",
					data: {
							lang: language,
							type: id,
							q: $("#searchfield").val()
					   },
					success: function(data){
						if(data!="") {
						$('#autocompletecontent').html(data);
						}
					}
				});	
} 


