var simpleTreeCollection;

$(document).ready(function(){
	
	simpleTreeCollection = $('.simpleTree').simpleTree({
		//autoclose: true,
		afterClick:function(node){
			//alert("text-"+$('span:first',node).text());
		},
		afterDblClick:function(node){
			//alert("text-"+$('span:first',node).text());
		},
		afterMove:function(destination, source, pos){
			//alert("destination-"+destination.attr('id')+" source-"+source.attr('id')+" pos-"+pos);
		},
		afterAjax:function()
		{
			//alert('Loaded');
		},
		animate:true
		//,docToFolderConvert:false
	});
	//expandez by default 
	expand("#mt_copii");
	expand("#mt_batrani");
	expand("#mt_cereri");
	expand("#mt_menaj");
	expand("#mt_servicii");
	
	//$("#data_nasterii").datepicker({showOn: 'button', buttonImage: '/extras/images/calendar.gif', buttonImageOnly: true, changeMonth: true, changeYear: true }, $.datepicker.regional['ro']);
	$("#data_nasterii").mask("99/99/9999");

	(function($) {
		$.datepicker.regional['ro'] = {
			clearText: 'Curat', clearStatus: 'Sterge data curenta',
			closeText: 'Inchide', closeStatus: 'Inchide fara schimbare',
			prevText: '&#x3c;Anterior', prevStatus: 'Arata luna trecuta',
			prevBigText: '&#x3c;&#x3c;', prevBigStatus: '',
			nextText: 'Urmator&#x3e;', nextStatus: 'Arata luna urmatoare',
			nextBigText: '&#x3e;&#x3e;', nextBigStatus: '',
			currentText: 'Azi', currentStatus: 'Arata luna curenta',
			monthNames: ['Ianuarie','Februarie','Martie','Aprilie','Mai','Junie',
			'Julie','August','Septembrie','Octobrie','Noiembrie','Decembrie'],
			monthNamesShort: ['Ian', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun',
			'Jul', 'Aug', 'Sep', 'Oct', 'Noi', 'Dec'],
			monthStatus: 'Arata o luna diferita', yearStatus: 'Arat un an diferit',
			weekHeader: 'Sapt', weekStatus: 'Saptamana anului',
			dayNames: ['Duminica', 'Luni', 'Marti', 'Miercuri', 'Joi', 'Vineri', 'Sambata'],
			dayNamesShort: ['Dum', 'Lun', 'Mar', 'Mie', 'Joi', 'Vin', 'Sam'],
			dayNamesMin: ['Du','Lu','Ma','Mi','Jo','Vi','Sa'],
			dayStatus: 'Seteaza DD ca prima saptamana zi', dateStatus: 'Selecteaza D, M d',
			dateFormat: 'mm/dd/yy', firstDay: 1,
			initStatus: 'Selecteaza o data', isRTL: false};
		$.datepicker.setDefaults($.datepicker.regional['ro']);
	})(jQuery);
	
	$('img.captify').captify({
		// all of these options are... optional
		// ---
		// speed of the mouseover effect
		speedOver: 'fast',
		// speed of the mouseout effect
		speedOut: 'fast',
		// how long to delay the hiding of the caption after mouseout (ms)
		hideDelay: 200,	
		// 'fade', 'slide', 'always-on'
		animation: 'slide',		
		// text/html to be placed at the beginning of every caption
		prefix: '',		
		// opacity of the caption on mouse over
		opacity: '0.9',					
		// the name of the CSS class to apply to the caption box
		className: 'caption-bottom',	
		// position of the caption (top or bottom)
		position: 'bottom',
		// caption span % of the image
		spanWidth: '100%'
	});
	
	$("#bang").scrollable({
		size: 1,
		clickable: false,
		loop: true,
		interval: 8000,
		speed: 900
		/*// when seek starts make items little transparent 
        onBeforeSeek: function() { 
            this.getItems().fadeTo(300, 0.2);         
        }, 
         
        // when seek ends resume items to full transparency 
        onSeek: function() { 
            this.getItems().fadeTo(300, 1); 
        } */
		//removed, ca facea ca trenu
	});
	
	$("#btnSondaj").click(
		function(){
			var idsond = $("#idsond").val();
			var radiouris = $("form input:radio[name='sondajopt']");
			var radiouri = radiouris.length;
			//alert(radiouri);
			var zelegdad = 0;
			var a  = 1;
			//for(a=1; a<=radiouri; $a++){
			for(var e in radiouris){
				var s2 = $("#sondajopt"+a).attr("checked");
				if(s2===true){
					//alert(a);
					zelegdad = $("#sondajopt"+a).val()
				}
				//alert(a + '-' + s2);
				a++;
			}
			if(zelegdad > 0){
				var datele = 'id_sondaj='+idsond+'&optiune='+zelegdad+'&ajax=da';
				$("#sondaj").load('/sondaj', {'id_sondaj': idsond, 'optiune': zelegdad, 'ajax': 'da'});
				//alert('x'+zelegdad);
				return false;
			}
			else {
				return false;
			}
			//var idsond = $().val();
			//$("#sondaj").load('/sondaj', datele)
		}
	);
	$("#mt_tarife").removeClass('doc');
	$("#mt_tarife").addClass('folder-open');
	$("#mt_selectia").removeClass('doc-last');
	$("#mt_selectia").addClass('folder-open-last');
	
	
	var COOKIE_NAME = 'afisare_anunt_reclama';
    //var ADDITIONAL_COOKIE_NAME = 'additional';
    var options = { path: '/', expires: 1 };
	var date = new Date();
    date=date.getTime();
	//alert(date);
	var cuki = $.cookie(COOKIE_NAME);
	cuki = parseInt(cuki);
	if(isNaN(cuki)){cuki=0;}
	//if(cuki>=10){ cuki=0; }
	if(cuki>=7){ cuki=0; }
	//alert(cuki);
	if(cuki==10){
		$(".a_reclama_p").ceebox();
		//$("#cee_box").css('top', '250px');
		$(".a_reclama_p").click();
		$("#cee_load").hide();
		$("#cee_box").css('top', '400px');
		//$.cookie(COOKIE_NAME, parseInt(cuki)+1, options);
	}
	$.cookie(COOKIE_NAME, parseInt(cuki)+1, options);
	
});

function validare_formular_oferta(ui){
	//alert(ui);
	return false;
}

function expand(expandnodeid)
{
simpleTreeCollection[0].nodeToggle($(expandnodeid, simpleTreeCollection[0])[0]);
}

/* Romanian initialisation for the jQuery UI date picker plugin. */
/* Written by Edmond L. (ll_edmond@walla.com). */
