var $j = jQuery.noConflict();


/*Cookie*/

function setCookie (name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function userChoice(menuId) {
	var d = new Date();
    var time = d.getTime() + 2592000;
	var menuId = parseInt(menuId);
    //setCookie("topchoice", menuId, time, '/');
	//setCookie("topChoice", menuId, d.toGMTString(), '/', false, false);
	if (menuId != '8')
	{
		setCookie("cssChoice", 1 + menuId, false, '/');
	} else {
		setCookie("cssChoice", '1' , false, '/');
	}
	return true;
}


/*End Cookie*/


$j(document).ready(function(){	

	$j('ul.lmenu li.switch > a').click(function(){
			//$j('ul.lmenu li.act').removeClass('act');
			//$j(this).parent().toggleClass('act');
			$j(this).parent().toggleClass('act');
			return false;
		});

	$j('a.external').click(function(){
			window.open(this.href);
			return false;
		});

	$j('#scroll').crawlLine({speed:3,crawElement:'#scrollText'});

	$j("#header input[name='search_string']").focus(function(){
			if (this.value == 'find ...') this.value = '';
	});

	$j("#header input[name='search_string']").blur(function(){
			if(!this.value.length){
				this.value = 'find ...';
			}
	});

	$j('#annons div.newsBlock a.title').click(function(){
		var o = $j(this).parent().parent().parent();
		if (o.hasClass('actNews')) {
			return true;
		} else {
			$j('#annons div.actNews').removeClass('actNews');
			o.addClass('actNews');
			return false;
		}
	});
	$j('#news div.newsBlock a.title').click(function(){
		var o = $j(this).parent().parent().parent();
		if (o.hasClass('actNews')) {
			return true;
		} else {
			$j('#news div.actNews').removeClass('actNews');
			o.addClass('actNews');
			return false;
		}
	});

});




/*Vote*/
var last_src = "";


function cms_vote_postDo(formName, inputName, nstext) {
	var fObjColl = document.getElementsByName(formName);

	var fObj = '';
	if (fObjColl) {
		fObj = fObjColl[fObjColl.length-1];
	}

	if(typeof(fObj) !== "object") return false;
	
	iObj = fObj.elements[inputName];
	
	if(typeof(iObj) === "undefined") return false;

	res = false;
	for(i = 0; i < iObj.length; i++)
		if(iObj[i].checked)
			res = iObj[i].value;


	if(res) {
		sc = document.createElement("script");
		sc.src = "/vote/post/" + res + "/?m=" + new Date().getTime();
		oTemplate = fObj.elements['system_template'];
		if((oTemplate instanceof Object) && (oTemplate.value.length)) {		
			sc.src = sc.src + "&template="+oTemplate.value;			
		}

		fObj.appendChild(sc);
	} else {
		if(nstext) {
			alert(nstext);
		}
	}
}

function rateElement(element_id, num) {
	lLib.getInstance().makeRequest("/vote/json_rate/" + element_id + "/" + num + "/", function() {} );
}

