jQuery(document).ready(function(){
			
			$('ol li input[type="submit"]').button({icons: {primary: "ui-icon-folder-collapsed"}, text: true });
			$('ol li input[type="button"]').button({icons: {primary: "ui-icon-folder-collapsed"}, text: true });
			
			$("a").simpletooltip();
			
			$("a.popup").fancybox({
				'titleShow'		: true,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'titlePosition' 	: 'over',
				'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Imaginea ' +  (currentIndex + 1) + ' / ' + currentArray.length + '  ' + title +'</span>';
			}
			});
			$("a.popup_url").fancybox({
				'titleShow'		: false,
				'scrolling' : 'yes',
				'width':'800',
				'height':'400',
				'autoScale' :	'true',
				'overlayOpacity' : 0.7 ,
				'type':'iframe',
				'onClosed' : function(){window.location=parent.window.location;}
			});
			
			
		

			cur_date=new Date($('#pg_date').val());
			//alert (cur_date);
			$('#pg_date').datepicker();
			$('#pg_date').datepicker("setDate", cur_date);
			$('#pg_date').datepicker('option', {dateFormat: 'yy-mm-dd'});
			//$('#pg_date').datepicker('option', {minDate: new Date()});
		
		$('#nsl_data').datepicker();
			$('#nsl_data').datepicker("setDate", cur_date);
			$('#nsl_data').datepicker('option', {dateFormat: 'yy-mm-dd'});
		

		function addMega(){
        $(this).addClass("hovering");
        }

      function removeMega(){
        $(this).removeClass("hovering");
        }

    var megaConfig = {
         interval: 50,
         sensitivity: 3,
         over: addMega,
         timeout: 50,
         out: removeMega
    };

    $("#siteMainMnu ul li.mega").hoverIntent(megaConfig);
	
	$('#siteMainMnu ul li a, a').hover(
					function() { $(this).addClass('hover-state'); }, 
					function() { $(this).removeClass('hover-state'); }
				);
	
	setTimeout(function() { $('div.ui-widget#uiwmsgok,div.ui-widget#uiwmsgerror').fadeOut('fast');}, 3500); // inchid mesajele de tip widget dupa 3 sec
	
	
	$('#fileField').change(function() {
	var nume;
	var nume_fis;
	//alert(nume);
	nume=$('#fileField').val();
	nume_fis=nume.substring(nume.lastIndexOf('\\')+1,nume.lastIndexOf('\.'));
	ext="."+nume.substring(nume.lastIndexOf('\.')+1,nume.length);
	$('#file_name').val(nume_fis);
	$('#extensie').html(ext);
	});
	
	////// CHECK ALL FILES
	
	$(".parentCheckBox").click(function() {
		$(this).parents('table:eq(0)').find('.chk_file').attr('checked', this.checked);	}
		);
	
	$('.chk_file').click(function() {
		if ($(this).parents('table:eq(0)').find('.parentCheckBox').attr('checked') == true && this.checked == false)
		$(this).parents('table:eq(0)').find('.parentCheckBox').attr('checked', false);
		if (this.checked == true) {
		var flag = true;
		$(this).parents('table:eq(0)').find('.chk_file').each(
		function() {
		if (this.checked == false)
		flag = false;
		}
		);
		$(this).parents('table:eq(0)').find('.parentCheckBox').attr('checked', flag);
		}
		}
		);
	/*
	$('table tr').click(function(event) {
			if (event.target.type !== 'checkbox') {
			  $('.chk_file', this).trigger('click');
			}
		  });
	*/
	////// CHECK ALL PAGES
	
	$(".parentCheckBox").click(function() {
		$(this).parents('table:eq(0)').find('.chk_page').attr('checked', this.checked);	}
		);
		
	$('.chk_page').click(function() {
		if ($(this).parents('table:eq(0)').find('.parentCheckBox').attr('checked') == true && this.checked == false)
		$(this).parents('table:eq(0)').find('.parentCheckBox').attr('checked', false);
		if (this.checked == true) {
		var flag = true;
		$(this).parents('table:eq(0)').find('.chk_page').each(
		function() {
		if (this.checked == false)
		flag = false;
		}
		);
		$(this).parents('table:eq(0)').find('.parentCheckBox').attr('checked', flag);
		}
		}
		);
	/*
		$('table tr').click(function(event) {
					if (event.target.type !== 'checkbox') {
					  $('.chk_page', this).trigger('click');
					}
				  });
		*/
		
		$("#lnkcautausr").click(function(){qc=$('#q').val(); window.location='q_'+qc+'_users_pg_0.htm';});
		$('#q').keypress(function(e){ if(e.which == 13){ qc=$('#q').val();window.location='q_'+qc+'_users_pg_0.htm'; }});
		
		$("#lnkcautapage").click(function(){qc=$('#qp').val(); window.location='q_'+qc+'_pages_pg_0.htm';});
		$('#qp').keypress(function(e){ if(e.which == 13){ qc=$('#qp').val();window.location='q_'+qc+'_pages_pg_0.htm'; }});
		
		$("#lnkcautasite").click(function(){qs=$('#qs').val(); window.location='q_'+qs+'_dgaspc_pg_0.htm';});
		$('#qs').keypress(function(e){ if(e.which == 13){ qs=$('#qs').val();window.location='q_'+qs+'_dgaspc_pg_0.htm'; }});
		
				
		$("#lnkcautaab").click(function(){qab=$('#qab').val(); window.location='q_'+qab+'_abonati_pg_0.htm';});
		$('#qab').keypress(function(e){ if(e.which == 13){ qab=$('#qab').val();window.location='q_'+qab+'_abonati_pg_0.htm'; }});
		
		$("#select_pg").change(function(){ctg=$('#select_pg option:selected').val(); window.location='ctg_'+ctg+'_pages_pg_0.htm';});
		
		$(".multifile").multifile({limit: 0, limitMessage: true, unique: true});
		
		
		$('.lnkaddopt').click(function(){ 
										$(this).parent().clone(true).insertAfter($(this).parent());
									   });
		$('.lnkdelopt').click(function(){ 
										$(this).parent().remove();
									   });
		
		
		
		
		
		
		
		
		

//Paging  and Slider Function
rotate = function(){
    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

    $(".paging a").removeClass('active'); //Remove all active class
    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

    //Slider Animation
    $(".image_reel").animate({
        left: -image_reelPosition
    }, 500 );

}; 

//Rotation  and Timing Event
rotateSwitch = function(){
    play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
        $active = $('.paging a.active').next(); //Move to the next paging
        if ( $active.length === 0) { //If paging reaches the end...
            $active = $('.paging a:first'); //go back to first
        }
        rotate(); //Trigger the paging and slider function
    }, 4000); //Timer speed in milliseconds (7 seconds)
};

rotateSwitch(); //Run function on launch

$(".image_reel a").hover(function() {
    clearInterval(play); //Stop the rotation
}, function() {
    rotateSwitch(); //Resume rotation timer
});	

//On Click
$(".paging a").click(function() {
    $active = $(this); //Activate the clicked paging
    //Reset Timer
    clearInterval(play); //Stop the rotation
    rotate(); //Trigger rotation immediately
    rotateSwitch(); // Resume rotation timer
    return false; //Prevent browser jump to link anchor
});

//Show the paging and activate its first link
$(".paging").show();
$(".paging a:first").addClass("active");

//Get size of the image, how many images there are, then determin the size of the image reel.
var imageWidth = $(".window").width();
var imageSum = $(".image_reel img").size();
var imageReelWidth = imageWidth * imageSum;

//Adjust the image reel to its new size
$(".image_reel").css({'width' : imageReelWidth});

		

$('select#pagecategs').multiselect2side({search: "Cauta: "	});

//swfobject.embedSWF("_includes/flash/Safernet-125x170.swf", "safernet", "125", "170", "9.0.0", "_includes/flash/expressInstall.swf");

var attributes = {}; 
var flashvars = {};
flashvars.file = "_includes/flash/dgaspc6-banner-sus.xml&transition=fade";
flashvars.width = "385";
flashvars.height = "115";
flashvars.shownavigation = "false";
flashvars.rotatetime = "3";
flashvars.shuffle = "false";
var params = {};
params.wmode = "false";
params.quality = "high";
params.salign = "t";
//swfobject.embedSWF("_includes/flash/imagerotator.swf", "bannerTopDr", "385", "115", "9.0.0", "_includes/flash/expressInstall.swf",flashvars, params, attributes);



});
