$(document).ready(function() {
    var config = {    
         sensitivity: 500, // number = sensitivity threshold (must be 1 or higher)    
         interval: 100,  // number = milliseconds for onMouseOver polling interval    
         over: doOpen,   // function = onMouseOver callback (REQUIRED)    
         timeout: 50,   // number = milliseconds delay before onMouseOut    
         out: doClose    // function = onMouseOut callback (REQUIRED)    
    };
    
    function doOpen() {
        $(this).addClass("hover");
        $('div:first',this).css({visibility: "visible", display: "none"}).show(300);
    }
 
    function doClose() {
	    $('div:first',this).hide(400);
	    $(this).removeClass("hover");
    }

    $("#menu li").hoverIntent(config);    
    

});


$(document).ready(function() {
	$('#side_kaart').css("z-index", "5");
	$('#side_niews').css("z-index", "6");
	$('#side_administration').css("z-index", "7");
	
   	$('#side_kaart').click(function() {
                $('#side_kaart').hide(50);
        $('#kaart_expanded').animate({left: '0'});
		$('#side_niews').show(500);
		$('#administration_expanded .close_button').trigger('click');
		$('#niews_expanded').animate({left: '-=300'});
    });
   	$('#kaart_expanded .close_button').click(function() {
          $('#kaart_expanded').animate({left: '-=300'});
		  $('#side_kaart').show(500);
		
	
    });
//  mai trebuie facut cand da click pe submit sa trimita datele si sa ascunda tabul


   	$('#side_niews').click(function() {
		$('#side_niews').hide(50);	
        $('#niews_expanded').animate({left: '0'});
		$('#side_kaart').show(500);

		$('#administration_expanded .close_button').trigger('click');
		$('#kaart_expanded').animate({left: '-=300'});
    });
   	$('#niews_expanded .close_button').click(function() {
          $('#niews_expanded').animate({left: '-=300'});
		  $('#side_niews').show(500);
    });

   	$('#side_administration').click(function() {
		$('#side_administration').hide(50);	
        $('#administration_expanded').animate({left: '0'});
		$('#side_kaart').show(500);
		$('#side_niews').show(500);		
		$('#niews_expanded').animate({left: '-=300'});
		$('#kaart_expanded').animate({left: '-=300'});		
    });
   	$('#administration_expanded .close_button').click(function() {
          $('#administration_expanded').animate({left: '-=300'});
          if(displayAdminMenu)
        	  $('#side_administration').show(500);		  
    });

	$(".niews_trigger").fancybox({
		'scrolling' : 'no',
		'titleShow'	: false,
		'padding' : '1px'
		});
	$(".faq_trigger").fancybox({
		'scrolling' : 'no',
		'titleShow'	: false,
		'padding' : '1px'
		});
	$(".minder_hinder_trigger").fancybox({
		'scrolling' : 'no',
		'titleShow'	: false,
		'padding' : '1px'
		});
	$(".roadwork_trigger").fancybox({
		'scrolling' : 'no',
		'titleShow'	: false,
		'padding' : '1px'
		});
        $(".homeImage_trigger").fancybox({
		'scrolling' : 'no',
		'titleShow'	: false,
		'padding' : '1px'
		});
	$(".contact_trigger").fancybox({
		'scrolling' : 'no',
		'titleShow'	: false,
		'padding' : '1px'
		});	
	$(".subscription_trigger").fancybox({
		'scrolling' : 'no',
		'titleShow'	: false,
		'padding' : '1px'
		});		
	
	$("#fancybox-close").each(function(){
		$(this).attr('title', 'Sluit dit venster');
	})
// enable scroller pe toate elementele 
	$('.scroller').jScrollPane();
	
// toggler pentru coloana de pe harta
  	$('.map_column_toggle').click(function() {
		$('#map_column').slideToggle();
		$('.map_column_toggle span').toggleClass("active");		
    });

// toggler pentru coloana de pe harta
      	$('.diverse_column_toggle span').live('click',function() {
		$('#diverse_column').slideToggle();
		$('.diverse_column_toggle span').toggleClass("active");		
    });


// toggler pentru toolbar de pe harta

        

	$('.toggler').toggle(function() {
	      $(this).parent().parent().animate({width: 29});
	      $('.toggler').addClass("active");
	      $(this).parent().parent().addClass("hideButton");
       }, function() {
           var width = 600;
           try{
               if(GToolbarWidth != null){
                width = GToolbarWidth;
               }
            }
            catch(ex){}
    	   var $this = $(this);
    	   $(this).parent().parent().animate({
    		   width: width
    		  }, function(){
    			  $('.toggler').removeClass("active");
    			  $this.parent().parent().removeClass("hideButton");
    	   });
	 });


// temporar - face switch intre harta si conetnt cand dai click pe butonul de home
	$('#map_container').addClass("invisible");

	$('.homebutton').toggle(function () {
		$('#content_home').addClass("invisible");
		$('#map_container').removeClass("invisible");
		setMapHeight();
       }, function() {
		$('#content_home').removeClass("invisible");
		$('#map_container').addClass("invisible");
		setContentHomeHeight();
	});

	function setContentHeight(){
		var wheight3 = $(window).height(); 
		$('#content').css('min-height', wheight3 - 215 + 'px');
	}
	setContentHeight();

	$(".alternate_rows tr:nth-child(odd)").addClass("odd");

	//$('#diverse').draggable();

});

//close panels
$('.closePanels').live('click', function(e, event){
    closePanels();
})

//close
function closePanels(){
    $('#kaart_expanded').animate({left: '-=300'});
    $('#side_kaart').show(500);

    $('#niews_expanded').animate({left: '-=300'});
    $('#side_niews').show(500);

    $('#administration_expanded').animate({left: '-=300'});
    if(displayAdminMenu)
        $('#side_administration').show(500);
}

//get the height of the window
function setContentHomeHeight(){
	$(window).resize(function() {
		var wheight1 = $(window).height(); 
		$('#content_home').css('height', wheight1 -  145 + '%');
	});
	var wheight1 = $(window).height(); 
	$('#content_home').css('height', wheight1 -  145 + '%');
}
function setMapHeight(){
	$(window).resize(function() {
		var wheight2 = $(window).height();
		if(wheight2 < 700)
			wheight2 = 830;
		$('#map_container').css('height', wheight2 - 180 + 'px');
		$('#map').css('height', wheight2 -  150+ 'px');
	});
	
	var wheight2 = $(window).height();
	if(wheight2 < 700)
		wheight2 = 830;
	$('#map_container').css('height', wheight2 - 180 + 'px');
	$('#map').css('height', wheight2 -  150+ 'px');
}

function setMapHeightForNewEditApprove(){
    var wheight2 = $(window).height();

    wheight2 = 1730;
    $('#content').css('height', wheight2 - 175 + 'px');
    $('#map_container').css('height', wheight2 - 135 + 'px');
    $('#map').css('height', wheight2 -  115+ 'px');
}




/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 


this.tooltip = function(xOff, yOff){
	/* CONFIG */		
		xOffset = xOff == null ? 10 : xOff;
		yOffset = yOff == null ? 20 : yOff;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".tooltipTitle").hover(function(e){
		this.t = this.title;
		this.title = "";									  
		//$("body").append("<p id='tooltip'>"+ this.t +"</p>");
                $("body").append("<div id='tooltip'>"+ this.t +"</div>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".tooltipTitle").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


this.tooltip2 = function(xOff, yOff){
    /* CONFIG */
            xOffset1 = xOff == null ? 10 : xOff;
            yOffset1 = yOff == null ? 20 : yOff;
            // these 2 variable determine popup's distance from the cursor
            // you might want to adjust to get the right result
    /* END CONFIG */
    $(".tooltipTitle2").hover(function(e){
            this.t = $(this).attr('content');
            //alert(this.t);
            //$(this).attr('content', "");
            $("body").append("<div id='tooltip2'>"+ this.t +"</div>");
            $("#tooltip2")
                    .css("top",(e.pageY - xOffset1) + "px")
                    .css("left",(e.pageX + yOffset1) + "px")
                    .fadeIn("fast");
},
    function(){
           // $(this).attr('content', this.t);
            $("#tooltip2").remove();
});
    $(".tooltipTitle2").mousemove(function(e){
            $("#tooltip2")
                    .css("top",(e.pageY - xOffset1) + "px")
                    .css("left",(e.pageX + yOffset1) + "px");
    });
};


// starting the script on page load
$(document).ready(function(){
    tooltip();

    $('.alternate_rows tr').live('click', function(){
        $('tr').removeClass('selectedRow');
        $(this).addClass('selectedRow');
        $(this).find('td :radio').each(function(){
            $(this).attr('checked', true);
        });
    });
});
       
