/*zmolo.com (2010|v1.50)*/

var str_array=new Array();
var href_array=new Array();
var mainimages=new Array();
var main_images_index=0;
var main_images_index_active=0;
var main_images_frame_duration=3000;
var transitionTime1 = 2000;



/*var news_id=0;
var ind=1;
var runNews;
var currentStr;
var currentTopNewsFrame=0;
var topNewsFrameDuration=5000;
var topNewsFrames = 0; */
var blinkImage="<img src='/im/blink.gif' style='margin-bottom:-2px;'>";
var currentSrc='';


function run_list(allnews){
	clearTimeout(runNews);
	ind=1;
	if (news_id>=allnews.length) news_id=0;
	objRun.href = href_array[news_id];
	currentStr = allnews[news_id];
	run_thru(currentStr);
}


function run_thru(val){
		if (ind<=val.length){
			objRun.innerHTML = val.substr(0,ind);
			ind ++;
			eval('runTimer='+setTimeout('run_thru("'+addslashes(val)+'")',50));
		} else {
			clearTimeout(runTimer);
			news_id++;
			eval("runNews="+setTimeout("run_list(str_array)",3000));
		}


}

function isdefined(variable) {
	return (typeof(window[variable]) == "undefined") ?  false: true;
}

function pauseRun(){
	objRun.innerHTML = currentStr;
	clearTimeout(runTimer);
	clearTimeout(runNews);
	return false;
}

function nextRun(){
	clearTimeout(runNews);
	clearTimeout(runTimer);
	news_id++;
	run_list(str_array);
	return false;
}


var popupWidth=300;

function refIm(imagename){
	var ima=document.getElementById(imagename);
	var src=ima.src;
	var regs=	/\&tst\=.*/;
	if (src.match(regs))
	{
		newshit="&tst="+Math.random();
		src = src.replace(regs,newshit);
	} else {
		src=src+"&tst="+Math.random();
	}
	ima.src = src;
	return false;
}


function putaj(){
	var fr=document.createElement('iframe');
	
	var content = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body>";

	content1="<form name=upd method=post action='/upd.php'><input type=hidden name=act value=''><input type=hidden name=passed value=''></form>";
	content += '</head>\n<body id=wsw>'+content1+'</body>\n</html>';

	fr.name="ajaxObj";
	fr.id="ajaxObj";
	fr.style.position='absolute';
	fr.style.margin=fr.style.padding='0px';
	fr.style.zIndex=1;
	fr.style.visibility='hidden';
	fr.style.display='block';
	fr.style.width=fr.style.height='0px';
	document.getElementsByTagName('body')[0].appendChild(fr);
	frm = document.getElementById ('ajaxObj');
	frm.src='/init.htm';
}


function create_fader(){
	var bodyObj=document.getElementsByTagName('body')[0];
	var fadeObj = document.createElement("div");
	fadeObj.setAttribute('id','fade');
	fadeObj.onclick = function () {destrpopcont();};
	fadeObj.style.display = 'none';
	fadeObj.style.position = 'absolute';
	fadeObj.style.top = '0';
	fadeObj.style.left = '0';
	fadeObj.style.zIndex = '20';
 	fadeObj.style.width = '100%';
	bodyObj.insertBefore(fadeObj, bodyObj.firstChild);
}



function sbmtr(formname,copyfrom,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	var getfrom=document.getElementById(copyfrom);
	if (keycode == 13){
		var func = new Function;
		func = getfrom.onclick;
		func();
		return false;
	}else return true;
}





function sbmt(formname,newparam){
	if (newparam)
	{
		eval("document.forms['"+formname+"'].su.value=newparam");
	}
	
	eval("document.forms['"+formname+"'].submit()");
}


function sbmtForm(formname){
	eval("document.forms['"+formname+"'].submit()");
	return false;
}

function wholePage(){
	
	var pageXscroll, pageYscroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		pageXscroll = document.body.scrollWidth;
		pageYscroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		pageXscroll = document.body.scrollWidth;
		pageYscroll = document.body.scrollHeight;
	} else { 
		pageXscroll = document.body.offsetWidth;
		pageYscroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	


	if(pageYscroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = pageYscroll;
	}

	if(pageXscroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = pageXscroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,pageXscroll,pageYscroll);
	return arrayPageSize;
}


function getPageScroll(){
	var pageYscroll;

	if (self.pageYOffset) {
		pageYscroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		pageYscroll = document.documentElement.scrollTop;
	} else if (document.body) {
		pageYscroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',pageYscroll); 
	return arrayPageScroll;
}


function getpopup(cond){
	var popupObj= document.getElementById ? document.getElementById("popup") : null;
	if (cond)
	{
		var coords= wholePage();
		var scroll=getPageScroll();
		var fadeObj = document.getElementById('fade');
		
		
		/*window.alert(coords[1]+'///'+coords[3]+'///'+coords[5]);*/
	
		hideNastyThings(0);
		chngvis('fade','block');
		fadeObj.style.height = (coords[1]+'px');
		
		fadeObj.style.display = 'block';

		selects = document.getElementsByTagName("select");
        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
        }

		/*popupObj.style.display = 'block';*/
		$(popupObj).fadeIn(400);

		popupObj.style.top = scroll[1]+(coords[3]-300)/2+'px';
		popupObj.style.left = (coords[0]-popupWidth)/2+'px';

	} 
	else 
	{
		popupObj.style.display = 'none';

	}

}

function destrpopcont() {
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
	}

	chngvis('fade','none');
	var objPop = document.getElementById ? document.getElementById("popcont") : null;
	$('#popup').fadeOut(400,function(){objPop.innerHTML = '';});
	
	/*chngvis('popup','none'); */
	hideNastyThings(1);
	
	return false;
}

function chngvis(name,val){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.style.display=val;

	var objok = document.getElementById ? document.getElementById('oks') : null;
	var objerror = document.getElementById ? document.getElementById('error') : null;
	
	if (objok)
	{
		objok.style.display='none';
	}

	if (objerror)
	{
		objerror.style.display='none';
	}

	return false;
}


function hideNastyThings(condition){

	var visibility = (condition==1) ? 'visible' : 'hidden'; 

	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
			//alert("getpopup");
			selects[i].style.visibility = visibility;
	}

	flashes = document.getElementsByTagName("object");
	for (i = 0; i != flashes.length; i++) {
			flashes[i].style.visibility = visibility;
	}
	
}


function getA(actpar,val,clockholder){
	var objaj = document.getElementById ? document.getElementById("ajaxObj") : null;
	var obJholder = document.getElementById ? document.getElementById(clockholder) : null;
	obJholder.style.display='block';

	var Owidth =	($(obJholder).width()-16)/2;
	var Oheight =	($(obJholder).height()-16)/2;

	
	obJholder.innerHTML="<img src='/im/clock4.gif' style='margin:"+Oheight+"px "+Owidth+"px;text-align:center;'>";

	$(obJholder).fadeIn(200);
	objaj.src = "/upd.php?act="+actpar+"&value="+val+"&tst="+Math.random();
	return false;
}

function setvalue(name,value){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.innerHTML = value;
}

function setvalue1(formname,elementname,elvalue){
	eval("document.forms['"+formname+"']."+elementname+".value = elvalue");
}




function SS(frm,alert){
	if (!(alert))
	{	
		Calert("Checking ....");
	} else {
		Cmessage("Checking ....");
	}
	
	document.forms[frm].submit();
	return false;
}



function addslashes(str) {
/*str=str.replace(/\'/g,'\\\'');*/
str=str.replace(/\"/g,'\\\"');
/*str=str.replace('/\\/g','\\\\');*/
/*str=str.replace(/\0/g,'\\0');*/
return str;
}



function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\\\/g,'\\');
str=str.replace(/\\0/g,'\0');
return str;
}



function chUp(action,formname,showalert){
	if (!(showalert))
	{
		Cmessage("<br><img src='/im/clock4.gif'><br><br>",1);
	} else {
		var processing = document.forms[formname].processing.value;
		/*Cmessage(processing,1); */
	}
	
	var objScript = document.getElementById ? document.getElementById("ajaxObj") : null;
	var reqLine='';
	var currform	=	eval("document."+formname);
	for(var i=0;i<currform.length;i++){
		reqLine+=currform[i].name+"="+escape(currform[i].value)+"&";
	}
	reqLine+="&frm="+formname+"&timestamp="+Math.random();
	objScript.contentWindow.document.forms['upd'].passed.value = reqLine;
	objScript.contentWindow.document.forms['upd'].act.value = action;
	objScript.contentWindow.document.forms['upd'].submit();
	return false;
}



function chgLoc(loc){
	var timerA;
	timerA=setTimeout(document.location.href=loc, 500);
}




function initAnchors()
{
	
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("rel") == "frametmb") {
			 anchor.onmouseover = function () {viewSlide(this.id); return false;};
			/* anchor.onmouseout = function () {runSlide(this.id);	return false;};	 */
		} else if (anchor.getAttribute("rel") == "bigtmb") {
			mainimages[main_images_index]=anchor; 
			main_images_index++;
			anchor.onmouseover = function () {swapBigImage(this); return false;};
			anchor.onclick	= function () {swapBigImage(this); return false;};
		}
	}

	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','tip');
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.zIndex = '90';
	
	objBody.insertBefore(objOverlay, objBody.firstChild);
}


function loadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}


function showTip1(obj){
	var tipid=obj.getAttribute("id");
	if (tipid == '1')
	{
		objtxt='';
		showtip('tip',objtxt,obj);
	}
	
}

function hideTip1(){
	var ObjTip = document.getElementById ? document.getElementById('tip') : null;
	ObjTip.style.display='none';
	
}

function showtip(tipid,objtxt,obj){
	var ObjTip = document.getElementById ? document.getElementById(tipid) : null;
	ObjTip.style.top = obj.offsetTop-45;
	ObjTip.style.left = obj.offsetLeft+50;
	if (ObjTip.style.display == 'none') 
	{
		
		ObjTip.style.display='block';
		ObjTip.innerHTML="<div>"+objtxt+"</div>";
	}
	
}

function hidetip(){	
	str='hideLayer()';				
	timerB=setTimeout('eval(str)', 500);
}

function hideLayer(){
	var ObjTip = document.getElementById ? document.getElementById("tip") : null;
	var objScript = document.getElementById ? document.getElementById("tipcontainer") : null;
	ObjTip.style.visibility="hidden";objScript.src = "/tip.php";

}


function updatetip(name,value){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.innerHTML = value;
	$('body').scrollTo( '#commentstart', 800, {queue:true} );
	/*$('body').scrollTop('commentstart')*/;
}


function movetip(obj){
	var ObjTip = document.getElementById ? document.getElementById("tip") : null;
	ObjTip.style.top=obj.clientY+document.body.scrollTop;
	ObjTip.style.left=obj.clientX+document.body.scrollLeft-250;
}




function startTopImagesAnimation(){

		 if (mainimages.length <=1)
		 {
			 return
		 } else {
			 if (main_images_index_active >= mainimages.length)
			 {
				 main_images_index_active=0;
			 }
			/* swapBigImage(mainimages[main_images_index_active]);	 */
			 
			imgPreload = new Image();

			imgPreload.onload=function(){
				swapBigImage(mainimages[main_images_index_active]);	 
				eval('imageTimer='+setTimeout('startTopImagesAnimation()',main_images_frame_duration));
				replaceBackground(main_images_index_active);
				main_images_index_active++;
				
				return false;
			}
			subObj=mainimages[main_images_index_active];
			imgPreload.src = subObj.getAttribute('href');


			
		}
		
}

function replaceBackground(index) {
	 $("#bigima").css("background-image","url("+mainimages[index].getAttribute('href')+")");
}



function viewSlide(id){

	/*clearTimeout(frameTimer);	*/
	if (window.continueTimer !==undefined)
	{	
		clearTimeout(continueTimer);
	}
	

	var iid = id.replace(/frametmb([^>]*)/gi, '$1');

	/*if (!isInteger(iid))
	{
	   iid = id.replace(/mainlink([^>]*)/gi, '$1');
	   
	}  */

	if (!isInteger(iid))
	{
	   iid = id.replace(/topnews([^>]*)/gi, '$1');
	   
	}
	

	for (var i=1; i<=topNewsFrames;i++ )
	{
		var topnews_name='#topnews'+i;
		/*var frame_name='#framecontainer'+i;*/
		var tmb='#frametmb'+i;

		if (i !== parseInt(iid))
		{
			$(topnews_name).hide();
			/*$(frame_name).hide(); */
			$(tmb).removeClass('active');
			document.getElementById('frametmb'+i).parentNode.className='';
		} else {

			document.getElementById('frametmb'+i).parentNode.className='active';
			$(tmb).addClass('active');
			$(topnews_name).show().animate({marginTop:'0px'},10);
			/*$(frame_name).show().animate({marginTop:'0px'},500); */
			
			currentTopNewsFrame=i;
			
		}
	}

}

function runSlide(id){

	var iid = id.replace(/frametmb([^>]*)/gi, '$1');
	continueTimer=setTimeout('startTopNewsAnimation()',200);
}

function navNews(direction){
	clearTimeout(frameTimer);
	navTopNews(direction);
}

function scaleText(direction){
	var container = document.getElementById('read');
	container.className= direction;
}

function swapBigImage(obj){

	if (currentSrc == $(obj).attr('href'))
	{
		return;
	}

	$('#mainimage').fadeOut(transitionTime1,
		function(){
			$('#mainimage').attr('src',obj.getAttribute('href'));
			/*$('#mainimage').fadeIn(transitionTime1); */
			$('#mainimage').fadeIn(5);
		}
	);

	currentSrc=$(obj).attr('href');
}


function refresh(){
	var actpar='listnews';
	var val=document.forms.listnews.lng.value+','+
			document.forms.listnews.rubric_id.value+','+
			''+','+
			''
		;
	/*window.alert(val);*/
	$("#headline").fadeOut(200,function() {getA(actpar,val,'headline')});
	return false;
}


function isInteger(s) {
  return (s.toString().search(/^-?[0-9]+$/) == 0);
}

function swap(id){
	$('#'+id).slideToggle(1000);
	return false;
}

$(document).ready(function(){
	
	initAnchors();
	startTopImagesAnimation();
	$('#r_checkin').jdPicker();
	$('#r_checkout').jdPicker();
});

