    function delMbook(){    	document.cookie = "ads=;";
		document.cookie = "inv=;";
		$(".tsel").attr('checked',false);
		$("#nrB").html("");
		$("#mbookz").hide("bounce",{times:3,distance:35}, 100);    }
	function parseVal(str){
		var res = new Array();       if ((str==undefined)||(str=="")){
       		return res;
       }else{
       		if (str.toString().charAt(0)==","){
       			res = str.toString().substr(1,str.length);
       		}
       		res = str.split(",");
       }
       return res;	}

	function parseCookie() {
	   var cookieList = document.cookie.split("; ");
	   var cookieArray = new Array();

	   for (var i = 0; i < cookieList.length; i++) {
	       var name = cookieList[i].split("=");
	       cookieArray[unescape(name[0])] =  unescape(name[1]);
	    }
	   return cookieArray;
	}

    function addValInb(val,id,act){
                if (act == 'del'){                    for (var i=0;i<val.length;i++){                    	if (val[i] == id){                    		val.splice(i,1);
                    		i--;                    	}                    }                }

                if(act == 'add'){                    val[val.length] = id;                }

     		return val;    }

	function bookmark(cat,id,th){        var cook = parseCookie(), ads = cook['ads'], act, inv = cook['inv'],adsStr,invStr;
        if (ads == 'undefined') ads = "";   if (inv == 'undefined') inv = "";
		ads = parseVal(ads);
		inv = parseVal(inv);

        if ($(th).attr("checked")){
            act = 'add';
	  	}else{
	  	    act='del';
	  	}

	  	if (cat == 'ads'){
	  		ads = addValInb(ads,id,act);
	  	}

	  	if (cat == 'inv'){	  		inv = addValInb(inv,id,act);	  	}

		var count = ads.length+inv.length;
		if (count < 1){$("#mbookz").hide("bounce",{times:3,distance:35}, 100);}else{$("#mbookz").show("bounce",{times:3,distance:35}, 100);}
        $("#nrB").html(ads.length+inv.length);

    	ads = ads.toString();
    	inv = inv.toString();

		document.cookie = "ads="+ads+"; ";
		document.cookie = "inv="+inv+"; ";	};

	function lookAdDetail(id){
		document.location = "#act=lad;idAd="+id;
		loadIn();
	}

	function slideSwitch() {

		var activeImg = $('#slideshow IMG.active');

		var nextImg = activeImg.next().length ? activeImg.next() : $('#slideshow IMG:first');

		if (activeImg.length == 0) {
			activeImg = $('#slideshow IMG:last');
		}

		activeImg.addClass('last-active');

		nextImg.css({opacity: 0.0}).addClass('active').animate(
			{opacity: 1.0},
			1000,
			function() {
				activeImg.removeClass('active last-active');
			}
		);
		
		setTimeout('slideSwitch()', headerImagesTimeout);
	}

	function loadIn(){

		$("#load").html("");
	    $("#loadimg").show();

		var scY = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
		if (scY > 400) window.scroll(0,400);

	    var vrs;

	    if (arguments.length != 0 && typeof arguments[0]!='undefined' && arguments[0]!=''){
	    	vrs = arguments[0];

	    	document.location.href = vrs;
	    }else{
			var hr = explode('#',document.location.href);
	        vrs = hr[1] || '';
	    }


	    if (vrs.charAt(0)=='#') {vrs = vrs.toString().substr(1,vrs.length);}

 		$.post('ajaxLoad/urlStat.php',{url:vrs},function(){});

	    $("#changeLang").attr("action",'#'+vrs);


				$.post('ajaxLoad/main.php',{vars:vrs},
					function(data){
						$("#load").html(data);
		            });

	}

	function rotate(){        setTimeout(rotate,timeBanerRotate);
        if ($(".rbr").length > 1)		$(".rbr:first").slideUp("slow", function() { $(".rbr:last").after($(".rbr:first").slideDown()); } );

		if ($(".lbr").length > 1)
		$(".lbr:first").slideUp("slow", function() { $(".lbr:last").after($(".lbr:first").slideDown()); } );

		if ($(".cbr").length > 1)
		$(".cbr:first").slideUp("slow", function() { $(".cbr:last").after($(".cbr:first").slideDown()); } );

	  /*if ($(".ubr").length > 1)
		$(".ubr:first").slideUp("slow", function() { $(".ubr:last").after($(".ubr:first").slideDown()); } );*/	}

    function show_ruls(){    	$("#regulament").dialog({
		                position:['center',10],
		         		modal: true,
		         		height:430,
		         		width:'60%',
		         		resizable:false,
		         		open: function(event, ui){$('body').css('overflow-x','hidden');$('.ui-widget-overlay').css('width','100%'); },
		   				close: function(event, ui){$('body').css('overflow-x','auto'); }
		  	 });    }

$('#login_username').keypress(
	function (event) {
	
		var key = (!event || !event.which) ? event.keyCode : event.which;
		
		if (key == 13) {
		
			if ($(this).val().length<3 || $('#login_userpass').val().length<3) {
				$("#date").css("color","#FF0000");
				$("#date").html("name>3 & password>3");
				return false;
			} else {
				$("#logg").submit();
			}
		}
	}
);

function searchA(val){loadIn("#act=search;search="+val); }
$(document).ready(
	function(){
         $("#reg_event").live('click',function(){$("#regulament_event").dialog({
			         			 title:'Esc Exit',
			         			 modal: true,
		 					     height: 520,
		 					     width: 740,
		 					     resizable: false,
                                 position: ['center',10],
		 					     open: function(event, ui){$('body').css('overflow-x','hidden');$('.ui-widget-overlay').css('width','100%'); },
   								 close: function(event, ui){$('body').css('overflow-x','auto');$('#dialog').html(); }
		 	});});
		/*contacts----------------------------------------*/
		$(".openContact").click(function(){			$("#contacte").dialog({
		                position:['center',10],
		         		modal: true,
		         		height:430,
		         		width:'60%',
		         		resizable:false,
		         		open: function(event, ui){$('body').css('overflow-x','hidden');$('.ui-widget-overlay').css('width','100%'); },
		   				close: function(event, ui){$('body').css('overflow-x','auto'); }
		  	 });		});
		/*end contacts----------------------------------------*/


        $("#sVal").click(function(){        	var val = $(this).val();
        	if (val == "Search"){$(this).val("");}        });
        $("#sVal").blur(function(){        	var val = $(this).val();
        	if (val==""){$(this).val("Search");}        });
        /*search-------------------------------------------
        $("#sBtn").click(function(){        	var val = $("#sVal").val();
        	if ((val.length>3)&&(val!="Search"))
        	loadIn("#act=search;search="+val);        });
        end search-------------------------------------------*/

		$("#searchsubmit").submit(function(){			var val = $("#sVal").val();
        	if ((val.length<3)||(val=="Search")){        		return false;        	}		});
        /*open bookmark--------------------------------------------------------*/
		var cooks = parseCookie(), ads = cooks['ads'], inv = cooks['inv'];
        if (ads == 'undefined') ads = "";   if (inv == 'undefined') inv = "";
		ads = parseVal(ads);
		inv = parseVal(inv);

		var count = ads.length+inv.length;
		if (count < 1){$("#mbook").hide();}else{$("#mbook").show();}
        $("#nrB").html(ads.length+inv.length);
        /*---------------------------------------------------------------------*/

		$(".loadComents").click(function(){			$(".loadComents").removeClass('selected');			$(this).addClass('selected');			$("#comCont").html('<span class="selected">Loading...</span>');
			$("#comCont").load("ajaxLoad/gbook.php?idCat="+$(this).attr('idCat')+"&tab=0");		});

	$("#openCom").click(
		function(){
			$("#comments").dialog(
				{
					position:['center',10],
					modal: true,
					height:530,
					width:'80%',
					resizable:false,
					open: function(event, ui) {
						$('body').css('overflow-x','hidden');
						$('.ui-widget-overlay').css('width','100%');
					},
					close: function(event, ui) {
						$('body').css('overflow-x','auto');
					}
				}
			);
	
			$('#comments').dialog(
				{
					dialogClass: "flora"
				}
			);
			
			$('.flora.ui-dialog').css(
				{
					position:"fixed"
				}
			);
		}
	);
	
	var mright = ($("#wrapper").width()-330);

	$("#mbook").css('left',mright);

	rotate();
	
	slideSwitch();

	$('.load').bind(
		'click',
		function() {
			var href = $(this).attr('href');
			loadIn(href);
			document.location.href = href;
			$("#error").remove();
		}
	);


	$(document).ajaxStart(
		function() {
			$("#loadimg").show();
			$(document).css('cursor','progress');
		}
	).ajaxStop(
		function() {
			$("#loadimg").hide();
			$(document).css('cursor','default');
		}
	);

	$("#res_pas").click(
		function() {
			$("#log").dialog("close");
			loadIn("#act=recPass");
		}
	);

	$(".loglink").click(
		function() {
		
			var logStatus = $(this).attr("status");
			
			if (logStatus == 1) {

				$("#log").dialog(
					{
						modal: true,
						height: 220,
						width: 320,
						resizable: false,
						bgiframe: true,
						buttons: {
							"Cancel": function() {
								$(this).dialog("close");
							},
							"Ok": function() {
								if (
									($("input[name='username']").val().length<3) ||
									($("input[name='userpass']").val().length<3)
								) {
									$("#date").css("color","#FF0000");
									$("#date").html("name>3 & password>3");
									return false;
								} else {
									$("#logg").submit();
								}
							}
						}
					}
				);
				
				$(".divloginput input[type='text']").focus();
				
			} else {
			
				$(location).attr('href', 'index.php?action=logoff');
			}
		}
	);
});
