function small_areas() 
{
  $("#zona_a_sm").mouseover(function () {
    $("#small_map").css('background-position','0 -229px');  
  });
  $("#zona_a_sm").mouseleave(function () {
    $("#small_map").css('background-position','0 0');  
  });
  
  $("#zona_b_sm").mouseover(function () {
    $("#small_map").css('background-position','0 -460px');  
  });
  $("#zona_b_sm").mouseleave(function () {
    $("#small_map").css('background-position','0 0');  
  });
  
  $("#zona_c_sm").mouseover(function () {
    $("#small_map").css('background-position','0 -690px');  
  });
  $("#zona_c_sm").mouseleave(function () {
    $("#small_map").css('background-position','0 0');  
  });
  
  $("#zona_d_sm").mouseover(function () {
    $("#small_map").css('background-position','0 -920px');  
  });
  $("#zona_d_sm").mouseleave(function () {
    $("#small_map").css('background-position','0 0');  
  });
  
  $("#zona_e_sm").mouseover(function () {
    $("#small_map").css('background-position','0 -1150px');  
  });
  $("#zona_e_sm").mouseleave(function () {
    $("#small_map").css('background-position','0 0');  
  });
  
  $("#zona_f_sm").mouseover(function () {
    $("#small_map").css('background-position','0 -1380px');  
  });
  $("#zona_f_sm").mouseleave(function () {
    $("#small_map").css('background-position','0 0');  
  });
  
  $("#zona_g_sm").mouseover(function () {
    $("#small_map").css('background-position','0 -1610px');  
  });
  $("#zona_g_sm").mouseleave(function () {
    $("#small_map").css('background-position','0 0');  
  });    
}

function big_areas() 
{
  $("#zona_a").mouseover(function () {
    $("#big_map").css('background-position','0 -415px');  
  });
  $("#zona_a").mouseleave(function () {
    $("#big_map").css('background-position','0 0');  
  });
  
  $("#zona_b").mouseover(function () {
    $("#big_map").css('background-position','0 -831px');  
  });
  $("#zona_b").mouseleave(function () {
    $("#big_map").css('background-position','0 0');  
  });
  
  $("#zona_c").mouseover(function () {
    $("#big_map").css('background-position','0 -1247px');  
  });
  $("#zona_c").mouseleave(function () {
    $("#big_map").css('background-position','0 0');  
  });
  
  $("#zona_d").mouseover(function () {
    $("#big_map").css('background-position','0 -1664px');  
  });
  $("#zona_d").mouseleave(function () {
    $("#big_map").css('background-position','0 0');  
  });
  
  $("#zona_e").mouseover(function () {
    $("#big_map").css('background-position','0 -2080px');  
  });
  $("#zona_e").mouseleave(function () {
    $("#big_map").css('background-position','0 0');  
  });
  
  $("#zona_f").mouseover(function () {
    $("#big_map").css('background-position','0 -2496px');  
  });
  $("#zona_f").mouseleave(function () {
    $("#big_map").css('background-position','0 0');  
  });
  
  $("#zona_g").mouseover(function () {
    $("#big_map").css('background-position','0 -2912px');  
  });
  $("#zona_g").mouseleave(function () {
    $("#big_map").css('background-position','0 0');  
  });    
}

function module_over()
{
  $('.modout').hover(function() {
		$(this).find('.modin').stop().animate({'top': '0'}, 400,'easeOutExpo');
	}, function() {
		$(this).find('.modin').stop().animate({'top': '167px'}, 400, 'easeInOutExpo');
	});
        
}

//home header sliding and clicking
//global variables for header sliding functions
var featured;
var featured_num;
var featured_text;
var featured_img;
var timer;
var previous = 0;
//set constants
var slide_speed_slow = 400;
var slide_speed_fast = 550;
var top_point = 0;
var bot_point = 400;
var pause_time = 3000;

//new header slide functions
function header_control (old_pos, up_down)
{  
  $('#controls').show();
  previous = old_pos;
  
  //calculate next slide position
  if (up_down == 1)
  {
    return timer = setTimeout('header_slide ('+ old_pos + ', ' + bot_point + ', 1, null)', pause_time);
  }  
    else
    {
      position = old_pos + 1;      
      
      $('#controls > li > a > img').hide();
      if (position < featured_num)
      {        
        $('#s'+position + ' > img').show();
        return header_slide(position, top_point, 0, null);
      }  
        else
        {
          $('#s0 > img').show();    
          return header_slide(0, top_point, 0, null);
        }       
    }  
}

//receives current slide, slideto position, slide speed for text , slide speed for image
//return must be on the longest interval animation callback
function header_slide (slide_current, slide_to, visible, clicked)
{
  $('#controls').hide();
  
  if (visible == 0)
  {
    $(featured_text[slide_current]).parent().show();  
  }
  $(featured_img[slide_current]).animate({'top': slide_to}, slide_speed_slow, 'jswing');    
  $(featured_text[slide_current]).animate({'top': slide_to}, slide_speed_fast, 'jswing', function() 
  {
    if (clicked == null)
      if (visible == 1)
      {
        $(featured_img[slide_current]).parent().hide();
        return header_control(slide_current, 0);
      }        
        else
        {          
          return header_control(slide_current, 1);  
        }
      else
      {
        return header_control(clicked, 0);      
      }      
  });
}


function init_header_slide ()
{  
  featured = $('div.featured');
  featured_num = featured.length;
  featured_text = $('div.featured > .twoCol');
  featured_img = $('div.featured > img'); 
  $('#s0 > img').show();  
  //wait and slide down the original slide
  return timer = setTimeout('header_slide (0, ' + bot_point + ', 1, null)', pause_time);  
}
//end of new header slide functions

$(document).ready(function() 
{
  //make image link functional
  $('div.featured > img').click(function() 
  {
    window.location = $(this).attr('alt');
  });
  
  if ($('div.featured').length > 1)
  {    
    init_header_slide();
    $('#controls > li > a').click(function () 
    {
      timer = clearTimeout(timer);      
      //needs to be decreased because header_control increments
      clicked = $(this).attr('href') - 1;
      header_slide (previous, bot_point, 1, clicked);
      return false;
    }); 
  }
  
  //la distributie
  big_areas();
  //la module generale
  small_areas();
  module_over();
  //la galerie
  $(".fancy").fancybox();
  //la contact
  $("#contactForm").validate({
    messages: 
    {
      name: "Va rugam introduceti un nume.",
      email: "Va rugam introduceti o adresa de e-mail.",
      phone: "Va rugam introduceti un numar de telefon.",
      message: "Va rugam introduceti un mesaj."      
    }
    
  });
  
});
