// common misc functions
// "#ajax_info_box").

site = {
    config: {
        css: {
            focusClass: 'setFocus'
        }
    }
}

var errorColor = '#ff9f75';

// show "Laduje..." red box on top right corner
function ajaxInfo()
{
   $().ajaxStart(function(){
   		$("#ajax_info_box").show();
   	}
	).ajaxStop(function(){
		$("#ajax_info_box").hide();
	});
}
// show error message near specyfied element
function putErrorInline(id,mess)
{
	id_attr = $(id).attr('id');
	$('#inline_'+id_attr).remove();
	sp = $('<span id="inline_'+id_attr+'" class="error_inline">'+mess+'</span>');
	$(id).after(sp);
}
// remove error box
function removeErrorInline(id)
{
	id_attr = $(id).attr('id');
	$('#inline_'+id_attr).remove();
}
// put error message on error list. Error list appear under header
function putOnErrorList(id,mess)
{
	$("#li_error_"+id).remove();
	li = $("<li id=\"li_error_"+id+"\">"+mess+"</li>");
	$("#error_list_top").append(li);
	$("#error_box_top").show().focus();
}
// remove element from error list
function removeOnErrorList(id)
{
	$("#li_error_"+id).remove();
}
//show single line error for specified time, default it's 400s
function displayError(mess,time)
{
//	console.log(mess);
	ttime = 4000;
	if(time == "no")
		$("#error_box_top").text(mess).show().focus();	
	else
	{
		if(time)
			ttime = time;
		$("#error_box_top").text(mess).show().focus().fadeOut(ttime);
	}
	
	/*$("#error_box_top").text(text).show();
	$("#error_box_top").fadeOut(1000);*/
}
// hide error box
function hideError()
{
	$("#error_box_top").hide();
}

// unused, should block interfac, now use thickbox method if necessary
function ajaxPostWithBlock(urlToExec,method,dataToSend,callback)
{
	$.ajaxSetup({
		type: method,
		url: urlToExec,
		global: false,
		success: function(dataToProcess)
			{
				$.unblockUI();
				callback(dataToProcess);
			},
		complete: $.unblockUI,
		start: $.blockUI,
		stop: $.unblockUI
	});
	$.ajax({ data:dataToSend });
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=")
	  if (c_start!=-1)
	    { 
	    c_start=c_start + c_name.length+1 
	    c_end=document.cookie.indexOf(";",c_start)
	    if (c_end==-1) c_end=document.cookie.length
	    return unescape(document.cookie.substring(c_start,c_end))
	    } 
	  }
	return ""
}

function setResizableElement(name,width){
   $(name).after($('<div class="resizable-bar" id="resizeS"></div>').css("width",width).css("margin-top","4px;"));
   $(name).Resizable(
	{
		minWidth: 500,
		minHeight: 100,
		maxWidth: 500,
		maxHeight: 500,
		minTop: 0,
		minLeft: 0,
		maxRight: 0,
		maxBottom: 0,
		dragHandle: false,
		handlers: {
			se: '#resizeSE',
			e: '#resizeE',
			ne: '#resizeNE',
			n: '#resizeN',
			nw: '#resizeNW',
			w: '#resizeW',
			sw: '#resizeSW',
			s: '#resizeS'
		}
	}
   );
}

$(document).ready(
	function()
	{
		ajaxInfo();
	//	$("#form_login").bind('submit',onLoginSubmit);
		ob = $("<img src=\"/templates/mollio-beat/images/plus.gif\" alt=\"rozwiń\" id=\"img-plus\" />");
		$("#title-nav-secondary").append(ob);
		$("#nav-secondary").show();
		$("#img-plus").attr("src","/templates/mollio-beat/images/minus.gif");
		
		// show/hide category box
		categoryBoxVal = getCookie('categoryBox');
		if(categoryBoxVal == '1')
		{
			$("#nav-secondary").show();
			$("#img-plus").attr("src","/templates/mollio-beat/images/minus.gif");
		} else if (categoryBoxVal == '0')
		{
			$("#nav-secondary").hide();
			$("#img-plus").attr("src","/templates/mollio-beat/images/plus.gif");
		}
		$("#title-nav-secondary").bind('click',function(){
				if($("#nav-secondary").css('display') == 'none')
				{
					$("#nav-secondary").show();
					$("#img-plus").attr("src","/templates/mollio-beat/images/minus.gif");
					setCookie('categoryBox','1',365)
				} else {
					$("#nav-secondary").hide();
					$("#img-plus").attr("src","/templates/mollio-beat/images/plus.gif");
					setCookie('categoryBox','0',365)
				}
				
			}).css('cursor','pointer');

		//show/hide tag box
		ob2 = $("<img src=\"/templates/mollio-beat/images/plus.gif\" alt=\"rozwiń\" id=\"img-plus2\" />");
		$("#title-nav-secondary2").append(ob2);
		//$("#tagcontent").hide();
		tagsBoxVal = getCookie('tagsBox');
		$("#img-plus2").attr("src","/templates/mollio-beat/images/minus.gif");
		//console.log(tagsBoxVal);
		if(tagsBoxVal == '1')
		{
			$("#tagcontent").show();
			$("#img-plus2").attr("src","/templates/mollio-beat/images/minus.gif");
			//setCookie('tagsBox','1',365)
		} else if (tagsBoxVal == '0')
		{
			$("#tagcontent").hide();
			$("#img-plus2").attr("src","/templates/mollio-beat/images/plus.gif");
			//setCookie('tagsBox','0',365)
		}
		$("#title-nav-secondary2").bind('click',function(){
				if($("#tagcontent").css('display') == 'none')
				{
					$("#tagcontent").show();
					$("#img-plus2").attr("src","/templates/mollio-beat/images/minus.gif");
					setCookie('tagsBox','1',365)
				} else {
					$("#tagcontent").hide();
					$("#img-plus2").attr("src","/templates/mollio-beat/images/plus.gif");
					setCookie('tagsBox','0',365)
				}
				
			}).css('cursor','pointer');
		
		//thickbox
		$(".login-a").attr('href','/login/?modal=true&width=250&height=230');
		$(".register-a").attr('href','/rejestruj/?modal=true&width=295&height=550');
		

	}
	
);