$(document).ready(function(){
	$("#font-size-maximize").click(function(){
		var currentFontSize = $('#content_text').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		$('#content_text').css('font-size', newFontSize);
		return false;
	});
	$("#font-size-minimize").click(function(){
		var currentFontSize = $('#content_text').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		$('#content_text').css('font-size', newFontSize);
		return false;
	});
	var originalFontSize = $('#content_text').css('font-size');
	  $("#resetFont").click(function(){
	  $('#content_text').css('font-size', originalFontSize);
	});

	$("a.video_preview").click(function(){
		$('#popup #popup_loader').show();
		var this_			=	$(this);
		var embed			=	this_.next().html();
		var body			=	this_.attr("alt");
		var arrPageSizes 	= 	___getPageSize();
		var arrPageScroll 	= 	___getPageScroll();
		$('#popup #popup_content').html(embed);
		$('#popup #pop_lezanta').html(body);
		$('#popup').css({
				top:	(arrPageSizes[3] / 10)-60,
				left:	(arrPageSizes[0] - $('#popup').outerWidth())/2
		}).show();
		$('#overlay').show();
		$('#popup #popup_loader').hide();
		$('#popup #popup_content').slideDown();
		return false;
	});
	
	$("#popup #pop_close").click(function(){
		$('#popup').hide();
		$('#overlay').slideUp("slow");
		$('#popup #popup_loader').show();
		$('#popup #popup_content').html('').hide();
		$('#popup #pop_lezanta').html('');
		return false;
	});
	
	
	$(".forma_signin").submit(function() {
		var password	=	1;
		var ids			=	new Array();
		var error 		= 	checkFillInputs($(this), password, ids);
		if (error) {
			return true;
		}
		return false;
	});
	$(".forma_signin").find(".check").focus(function () {
		$(this).removeClass("form_error");
	});

	$(".forma").submit(function() {
		var password	=	0;
		var ids			=	new Array();
		var error 		= 	checkFillInputs($(this), password, ids);
		if (error) {
			return true;
		}
		return false;
	});
	$(".forma").find(".check").focus(function () {
		$(this).removeClass("form_error");
	});	
	
	$(".forma_new_pass").submit(function() {
		var password	=	1;
		var ids			=	new Array();
		var error 		= 	checkFillInputs($(this), password, ids);
		if (error) {
			return true;
		}
		return false;
	});
	$(".forma_new_pass").find(".check").focus(function () {
		$(this).removeClass("form_error");
	});
	
	
		
	$(".JfixValue_").focus(function(){
		var this_  =  $(this);
		var value  =  this_.attr('title');
		if(this_.val().trim()=='' || this_.val().trim()==value){
			this_.val('');
		}
	});
	
	$(".JfixValue_").blur(function(){
		var this_  =  $(this);
		var value  =  this_.attr('title');
		if(this_.val().trim()=='' || this_.val().trim()==value){
			this_.val(value);
		}
	});
	$(".JfixValue_").each(function (i) {
		var this_  =  $(this);
		var value  =  this_.attr('title');
		this_.val(value);
	});
	
	
	$("#vote_button").click(function(){
		var randomnumber=Math.floor(Math.random()*11);
		var str = $("#poll_form").serialize();
		
		
		
		//alert(str+str.search("answer"));
		
		//return false;
		if(str.search("answer")!=-1){
			$("#pop_edit_templates_form").html('<center><img src="images/loading.gif" /></center>');
			$.ajax({
			   type: "POST",
			   url: "ajax.php",
			   data: str+"&a=cast_vote&refresh_cashe="+randomnumber,
			   dataType: "html",
			   success: function(results){
					$("#poll_form").html(results);
			   },
			   error: function(XMLHttpRequest, textStatus, errorThrown){
					alert('Error Ajax pop_edit_templates '+textStatus+'  '+errorThrown);
			   }
			});
		}else{
			alert('Παρακαλώ συμπληρώστε την απάντηση σας.');
		}

		
		
	});

	$("#event_photo").hover(
		function(){
			var this_	=	$(this);
			this_.css({"backgroundPosition": "0px -75px"});
		},
		function(){
			var this_	=	$(this);
			this_.css({"backgroundPosition": "0px 0px"});
		}
	);
	
	
});
var loader_img	=	'<img src="/images/ajax-loader.gif" alt="load" title="load"/>';
function checkFillInputs(forma, password, ids){
	var inputs = forma.find(".check").get();
	var i=0;
	var empty=true;
	for(i=0; i<inputs.length; i++){
		if(jQuery.trim($(inputs[i]).val())==''){
			empty = false;
			$(inputs[i]).addClass("form_error");						
		}		
	}
	var msg = '';
	
	if(!empty){
		msg += "Παρακαλώ συμπληρώστε όλα τα υποχρεωτικά στοιχεία.\n\n";
	}
	
	if(password){
		if($("#password").val() != $("#password2").val()){
			msg += "Το Password δεν είναι ίδιο με το Επαλήθευση Password.\nΠαρακαλώ συμπληρώστε σωστά τον κωδικό σας.\n\n";
			empty = false;
		}
		
	}
	
	if(ids.length>0){
		for(i=0; i<ids.length; i++){
			//alert("#"+ids[i]);
			//alert($("#"+ids[i]).attr("checked"));
			if(!$("#"+ids[i]).attr("checked")){
				msg	+= $("#"+ids[i]).next().html()+"\n\n";
				empty = false;
			}
		}
	}
	
	if(msg!=''){
		alert(msg);
	}
	
	return  empty;
}
function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

function ___getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};


function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}