$(document).ready(function(){
	
	$("#quizSet").jCarouselLite({
		btnNext: "#qs-next",
		btnPrev: "#qs-prev",
		//auto: 6600,
		speed: 400,
		visible:2,
		scroll:2
	});
	
	$("#slideSet").jCarouselLite({
		btnNext: "#ss-next",
		btnPrev: "#ss-prev",
		//auto: 6600,
		speed: 400,
		visible:4,
		scroll:4
	});
	
	
	
});


function show_leadnews(n){
	
	for(i=1; i<=5; i++){
		var obj = document.getElementById("ln_"+i);
		var btn = document.getElementById("b" + i);
		var item = document.getElementById("item_" + i);
		
		obj.style.display = "none";
		item.style.display = "none";
		btn.className = "blockTeaserBtn notFirst";
	}
	
	var elmPic = document.getElementById("ln_" + n);
	var elmBtn = document.getElementById("b" + n);
	var elmItem = document.getElementById("item_" + n);
	var elmLink = document.getElementById("a" + n);
	 
	
	elmPic.style.display = "block";
	elmItem.style.display = "block";
	elmBtn.className = "blockTeaserBtn selected";
	elmLink.style.position = "absolute";
	elmLink.style.display = "block";
}

function out_leadnews(n){
	
	var obj = document.getElementById("b" + n);
	var elm = document.getElementById("item_" + n);
	
	if(elm.style.display == "none"){
		obj.className = "blockTeaserBtn notFirst";
	}
	
}

function slide_storage(){
	
	var storage = document.getElementById('storage');
	
	if(storage.style.display == 'block'){
		$('#storage').hide(0);
		$('#caption').show(150);
	}else{
		$('#storage').show(150);
		$('#caption').hide(0);
	}
}

function slide_showHome(){
	
	var hold_1 = document.getElementById('holder_1');
	var hold_2 = document.getElementById('holder_2');
	var currID = hold_2.style.display == 'block' ? hold_2 : hold_1;
	
	if(currID == hold_1) {
		$('#holder_1').fadeOut(0);
		$('#holder_2').fadeIn(700);
	} else {
		$('#holder_2').fadeOut(0);
		$('#holder_1').fadeIn(700);
	}
}

function itquizHome(limit, direction, single){
	
	for(i=1; i <= limit; i++){
	
		if($("#quiz_" + i).css("display") == 'block'){
		
			nexti = ((i + 1) > limit) ? 1 : (i + 1);
			previ = (i - 1) < 1 ? limit : (i-1);
			step = direction ? nexti : previ;
			
			$(".sbquiz .holder").fadeOut(0);
			$("#quiz_" + step).fadeIn(500);
			
			if(single){
				$("#quiz_" + step+1).fadeIn(500);
			}
			break;
		}
	}
}

function createAjaxObj(){
	var httprequest=false
	if (window.XMLHttpRequest){
		httprequest=new XMLHttpRequest()
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml')
	}
	else if (window.ActiveXObject){
		try {
			httprequest=new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e){
			try{
				httprequest=new ActiveXObject("Microsoft.XMLHTTP");
			}	
			catch (e){}
		}
	}
	return httprequest
}

/* recommend news */

var ajaxRecomm=new Object()
ajaxRecomm.basedomain="http://"+window.location.hostname
ajaxRecomm.ajaxobj=createAjaxObj()
ajaxRecomm.filetype="txt"
ajaxRecomm.addrandomnumber=1

ajaxRecomm.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
	ajaxRecomm.ajaxobj=createAjaxObj()
	if (ajaxRecomm.addrandomnumber==1)
    var parameters=parameters+"&ajaxcachebust="+Math.floor(Math.random() * 1000000);
	
	if (this.ajaxobj){
		this.filetype=filetype
		this.ajaxobj.onreadystatechange=callbackfunc
		this.ajaxobj.open('GET', url+"?"+parameters, true)
		this.ajaxobj.send(null)
	}
}

function recommendNews(id, vote){
	
	if(vote == 'yes') vote = 1
	else if(vote == 'no') vote = 0
	else return;
	
    var params = "nid=" + id + "&vote=" + vote + "&rand=" + Math.random();
	ajaxRecomm.getAjaxRequest("/procedures/process_recommends.php", params, processGetPostRecommends, "txt");
}

function processGetPostRecommends(){
	var ret_val = ""
	var myajax=ajaxRecomm.ajaxobj
	var myfiletype=ajaxRecomm.filetype
	if (myajax.readyState == 4){
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){
			if (myfiletype=="txt") 
				ret_val = myajax.responseText
			else 
				ret_val = myajax.responseXML
		}
	}
    
	//set cookie and reload
	
	var id = parseInt(ret_val);
	if(!id) return;
	
	//get cookie value
	var cookieValue = '';
	var cookies = document.cookie.split(';');
	for (i=0; i<cookies.length; i++ ){
		cookieData = cookies[i].split('=');
		
		// trim left/right whitespace
		cookieName = cookieData[0].replace(/^\s+|\s+$/g, '');
		if(cookieName == 'recommended') {
			cookieValue = cookieData[1];
		}
	}
	
	//set new value
	var newCookie = id + '_' + cookieValue;
	var d = new Date();                               
	d.setDate(d.getDate()+2);                               
	window.document.cookie = "recommended=" + newCookie + ";path=/; expires=" + d.toUTCString();
	location.reload();
}

function submitQuiz(isCorect, aNumber, qNumber){

	$("#quizCurrent").hide(100);
	$(".quizAns").fadeIn(300);
	//$(".quizAns").slideDown(300);
	
	if(isCorect){
		$("#quizRezult").addClass("correct");
		$("#quizRezult").html("ֲונום מעדמגמנ");
	} else {
		$("#quizRezult").addClass("wrong");
		$("#quizRezult").html("ֳנורום מעדמגמנ"); 
	}
	
	var form = document.getElementById('quiz_form');
	form.answerNumber.value = aNumber;
	
}
