
$(document).ready(function(){
	$(".star-rating").children().hide();
	$(".star-rating-noscript").css('display','none');
	
	$('.star-rating-container').each(function(){
		var rating=$(this).find(".star-rating");
		var caption=$('<span>Szavazáshoz <a href="crevo/login">jelentkezz be</a></span>');
		rating.stars({inputType:'select',disabled:true});
		caption.appendTo(rating);
	});
});

//--~--~--~--~--~--~--
// Crevo JS engine
// - Wildfire -
//--~--~--~--~--~--~--

var $crevo={
	id:function(id){return document.getElementById(id);},
	ex:function(e){
		x=e.offsetLeft;
		if(e.offsetParent){while(e=e.offsetParent){x+=e.offsetLeft;}}
		return x;
	},
	ey:function(e){
		y=e.offsetTop;
		if(e.offsetParent){while(e=e.offsetParent){y+=e.offsetTop;}}
		return y;
	},
	opacity:function(e,i){
		e.style.filter='alpha(opacity='+i+')';
		i=i/100;
		i=i.toString();
		if(i.length==3){i+='0';} 
		e.style.MozOpacity=i;
		e.style.opacity=i;
	},
	createElement:function(e){return document.createElement(e);},
	parent:function(e,n){
		if(!n){
			return e.parentNode;
		}else{
			n=n.toUpperCase();
			var p=e.parentNode;
			var i=0;
			while(p.nodeName!=n && p.nodeName!='HTML'){p=p.parentNode;}
			return p;
		}
	},
	addEvent:function(obj,evType,fn,useCapture){
		if(obj.addEventListener){
			obj.addEventListener(evType,fn,useCapture);
			return true;
		}else if(obj.attachEvent){
			var r=obj.attachEvent("on"+evType,fn);
			return r;
		}else{
			alert("Handler could not be attached");
		}
	},
	request:function(a,m,p,f){ //address/method/parameters/function
		var xmlHttp;
		if(window.XMLHttpRequest){xmlHttp=new XMLHttpRequest();}else if(window.ActiveXObject){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
		if(xmlHttp!=null){
			xmlHttp.onreadystatechange=function(){
				if(xmlHttp.readyState==4){
					if(xmlHttp.status==200){
						var r=new String;
						r=xmlHttp.responseText;
						f(r);
					}else{alert('Hiba: '+xmlHttp.status+'\r\n'+xmlHttp.statusText);}
				}
			}
			switch(m){
				case 'GET':
					xmlHttp.open('GET',a,true);
					xmlHttp.send(null);
				break;
				case 'POST':
					xmlHttp.open('POST',a,true);
					xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=utf-8');
					xmlHttp.send(p);
				break;
			}
		}else{alert('Your browser does not support AJAX!');}
	},
	scrollX:function(){return (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;},
	scrollY:function(){return (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;},
	clientW:function(){return (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth;},
	clientH:function(){return (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;}
};

var $id=$crevo.id;
var $ex=$crevo.ex;
var $ey=$crevo.ey;
var $opacity=$crevo.opacity;
var $createElement=$crevo.createElement;
var $parent=$crevo.parent;
var $request=$crevo.request;
var $scrollX=$crevo.scrollX;
var $scrollY=$crevo.scrollY;
var $clientW=$crevo.clientW;
var $clientH=$crevo.clientH;
var $addEvent=$crevo.addEvent;


function popup(url){$.jqURL.loc(url,{w:450,h:300,wintype:'_blank'});}

//Image window
function iwin(url){
	//window.open(url,'crevo','top='+((screen.height-600)/2)+',left='+((screen.width-600)/2)+',width=600,height=600,scrollbars=1');
	imgPreview(url);
}

//Editor image preview
function imgPreview(url){
	$('#preview').css('display','block');
	$('#previewimg').html('<img src="'+url+'" width="900" onload="imgPreviewPos()" />');
}

function imgPreviewClose(){
	//window.scrollBy(0,$ey($id("editor")));
	$(window).scrollTo($('#editor'),800,{onAfter:function(){$('#preview').css('display','none')}});
	return false;
}

function imgPreviewPos(){
	$(window).scrollTo($("#preview"),800);
	//window.scrollTo(0,$ey($id("editor"))+$id("editor").offsetHeight);
}

//Form validation
function valid(){
	this.empty=function(e,m){if(e.value==''){alert(m);e.focus();return false;}else{return true;}}
	this.equal=function(e1,e2,m){if(e1.value!=e2.value){alert(m);e2.focus();return false;}else{return true;}}
	this.minlength=function(e,i,m){if(e.value.length<i){alert(m);e.focus();return false;}else{return true;}}
	this.email=function(e,m){if(!/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i.test(e.value)){alert(m);e.focus();return false;}else{return true;}}
	this.check=function(e,m){if(!e.checked){alert(m);e.focus();return false;}else{return true;}}
	this.sel=function(e,v,m){if(e.value==v){alert(m);e.focus();return false;}else{return true;}} //value

	var cParent;
	var cElement;
	var cFunction0;
	var cFunction1;
	var cMessage='';
	var cStatus=false;
	this.cSubmit=function(t){
		if(t==1){
			cStatus=true;
			eval(cFunction0);
		}else{
			alert(cMessage);
			eval(cFunction1);
			cElement.value='';
			cElement.focus();
			return false;
		}
	}
	this.captcha=function(p,e,f0,f1,m){
		if(!cStatus){
			cParent=p;
			cElement=e;
			cMessage=m;
			cFunction0=f0;
			cFunction1=f1;
			$request('http://www.crevo.hu/crevo/ajax/captcha/'+e.value,'GET','',valid.cSubmit);
			return false;
		}else{
			cStatus=false;
			return true;
		}
	}
}

var valid=new valid();