

var row_width = "420px";
var row_prefix = "news_row_";
var ROWS = Array();
var browser=navigator.appName;


var parent_top = 0;


var parent_height = 600;

var page_height = 946;
var default_speed = 1;
var interval = 50;
var speed = default_speed;

// For subsection images change
var subsection_images = new Array();
var subsection_images_text = new Array();

// Change the image on top of the page as interval calls it
function change_subsection_image()
{
   if (subsection_images.length > 1)
   {
      var rand = Math.floor(Math.random() * subsection_images.length);
      if ($("#section_image").attr("src") != subsection_images[rand])
      {
         var text = decodeURI(subsection_images_text[rand]);
         $("#section_image").fadeTo('slow', 0.1);
         $("#section_image").attr("src", subsection_images[rand]);
         $("#section_image").attr("alt", text);
         $("#section_image").attr("title", text);
         $("#image_author").text(text);
         $("#section_image").fadeTo('slow', 1);
      }

   }
}


function add_row(id)
{
   //window.setInterval("move_up('" + id + "');", interval);
   ROWS[ROWS.length] = id;
}

function move_all_up()
{
 $(".news_row").each(function() {

      //move_up($(this).attr("id"));
      $(this).css("top", parseInt($(this).css("top")) - 1);
      var offset = $(this).offset();
      var top = parseInt(offset.top);
      var height = parseInt($(this).height());
      //var top_clip = (parseInt(parent_top) - top);

      // Place in the end
      if ((height + top) < 0)
      {
         $(this).css("top", get_bottom() + "px");
      }
    });
}



function get_bottom()
{
   var bottom = 0;
   $(".news_row").each(
      function()
      {
         var top = parseInt($(this).css("top")) + parseInt($(this).height());
         if (top > bottom)
         {
            bottom = top;
         }
      }
   );

   return (bottom);
}

function get_top()
{
   var bottom = 0;
   for (var i = 0; i < ROWS.length; i++)
   {
      var temp = parseInt(document.getElementById(ROWS[i]).offsetHeight + document.getElementById(ROWS[i]).offsetTop);
      if (temp < bottom)
      {
        bottom = temp;
      }
   }
   return (bottom + 3);
}



function operate_course(id, obj, full_year)
{
   var course =  document.getElementById(id);
   var display = course.style.display;

   if (display == 'none')
   {
      course.style.display = '';
      course.className = 'background_section_light_color';

   }
   else
   {
      course.style.display = 'none';
   }
         opearate_plus(obj, full_year);
}

function opearate_plus(obj, full_year)
{
   var spans;
   // If it's full year course, we want to indicate all minuses
   if (full_year == 0)
   {
     spans  = obj.getElementsByTagName('SPAN');
   }
   else
   {
      spans  = obj.parentNode.getElementsByTagName('SPAN');
   }


   // Every second span contains a minus
   if (spans.length > 1)
   {
      for (var i = 1; i < spans.length; i = i + 2)
      {

          var plus_span = spans[i];
         if (plus_span != '')
         {
            if (plus_span.innerText == '+')
            {
               plus_span.innerText = '-';
               plus_span.parentNode.parentNode.style.borderBottomWidth = 0;
            }
            else
            {
               plus_span.innerText = '+';
               plus_span.parentNode.parentNode.style.borderBottomWidth = 1;
            }
         }
      }
   }

}

// Opens and closes the "Contact us"

function operateContactUs()

{

   var display = document.getElementById('contact_us_expanded_div').style.display;

   if (display == '' || display == 'none')

   {

      expand_contact_us();

   }

   else

   {

      collapse_contact_us();

   }

}



function expand_contact_us()

{

         document.getElementById('contact_us_expanded_div').style.display = 'block';

      document.getElementById('contact_us_div').style.display = 'none';

      if (document.getElementById('month_image_div'))

      {

         document.getElementById('month_image_div').style.top = 525;

      }

      if (document.getElementById('open_day_div'))

      {

         document.getElementById('open_day_div').style.top = 760;

      }

}



function collapse_contact_us()

{

         document.getElementById('contact_us_expanded_div').style.display = 'none';

      document.getElementById('contact_us_div').style.display = 'block';

      if (document.getElementById('month_image_div'))

      {

         document.getElementById('month_image_div').style.top = 325;

      }

      if (document.getElementById('open_day_div'))

      {

         document.getElementById('open_day_div').style.top = 560;

      }

}

function validate_search()
{

   if (document.getElementById('search').value.length < 3)

   {

      alert("חיפושך קצר מדי");

      document.getElementById('search').focus();

   }

   else

   {

      document.getElementById('search_form').submit();

   }

}

var about_div_height = "";

$(document).ready(function() {


      $(".work_info_div").fadeTo("fast", 0.7);
      $(".lightbox").lightBox();            
//$('a:has(img)').lightbox();
      $("a img[class!='no_fade']").hover(function() {
         $(this).fadeTo("fast", 0.6);
      } ,
      function() {
         $(this).fadeTo("fast", 1);
      } );

      setInterval('change_subsection_image();', 10000);

      setTimeout("show_news_with_delay()", 1000);

   var sum_heights = 0;
   var offset = $(".news_div").offset();


   // Place news rows and initialize
   $(".news_row").each(function(index) {

      $(this).css("top", sum_heights);

      sum_heights += $(this).height();


    });

      setInterval("move_all_up();", 100);

   $(".about_div span span:first").show();

      $(".plus_span").toggle(function() {
            $(this).css("background-image", "url('/site/images/minus.png')");

            about_div_height = $(".about_div").height();
            $(this).parent().find(".short_description").hide("slow");
            $(this).parent().find(".full_description").show("slow");

            $(".about_div").animate({height:$(".inner_about_div").height()}, 500);
               $(".inner_about_div").css("overflow", "auto");

            move_news_down();
         },
         function() {
            $(this).css("background-image", "url('/site/images/plus.png')");
            $(this).parent().find(".full_description").hide("slow");
            $(this).parent().find(".short_description").show("slow");

            $(".about_div").animate({height:about_div_height}, 500);
               $(".inner_about_div").css("overflow", "hidden");

            move_news_up();
         }
      );
   }// ready
);

function show_news_with_delay()
{
   $(".news_div").css("visibility", "visible");

}



function move_news_down()
{

   page_height = page_height + 290;
      parent_top += 220;
   parent_height -= 200;
   $(".gallery_background_sheet .news_div").css("height", "230px");
}

function move_news_up()
{

   page_height = page_height - 290;
   parent_top -= 220;
   parent_height += 200;
   $(".inner_about_div").scrollTop(0);
   $(".gallery_background_sheet .news_div").animate({"height": "430px"}, 500);
}





