

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


var init_parent_top = 0;

var parent_top = init_parent_top;


var parent_height = "380px";
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);
      }

   }
}

// Scrolls each news object up
function move_up(object_id)
{
   var object = document.getElementById(object_id);
   var t = parseInt(object.offsetTop);
   var top_clip = 0;

   // Init
   if (object.style.top == '')
   {
      object.style.top = parent_top;
   }

   // Move up
   object.style.top = parseInt(object.style.top) - speed;

   // Cut the top part
   if (t < parseInt(parent_top))
   {
      // That's very important, since when we later cut the bottom part, the item could still need
      // the top part to be cut too. So we save it now
      top_clip =  (parseInt(parent_top) - t);
      var clip = "rect(" + top_clip + "px, " + row_width + ", " + object.offsetHeight + ", 0px)";
      object.style.clip = clip;

   }

   // Put in the end
   if ((object.offsetHeight + object.offsetTop) < parseInt(parent_top))
   {
      var clip = "rect(0px, " + row_width + ", " + object.offsetHeight + ", 0px)";
      object.style.clip = clip;
      object.style.top = get_bottom() + "px";
   }

   // Cut the bottom part
   if ((object.offsetHeight + object.offsetTop) > parseInt(parent_top) + parseInt(parent_height))
   {
      var clip = "rect(" + top_clip + "px, " + row_width + ", " + (10 + (parseInt(parent_height) + parseInt(parent_top)) - parseInt(object.offsetTop)) + "px, 0px)";
      object.style.clip = clip;
   }
}

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

function move_all_up()
{
 jQuery.each(ROWS, function() {
      move_up(this);
    });
}

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

function get_bottom()
{
   var bottom = 0;
   for (var i = 0; i < ROWS.length; i++)
   {
      var temp = Math.floor(parseInt(document.getElementById(ROWS[i]).offsetHeight + document.getElementById(ROWS[i]).offsetTop));
      if (temp > bottom)
      {
        bottom = temp;
      }
   }
   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 validate_form()
{
   var name = document.getElementById('name');

   if (name.value.length < 3)
   {
      alert('יש להזין שם מלא');
      name.focus();
   }
   else
   {
      pageTracker._trackEvent("All_Lead_Forms", "Submit");

      document.getElementById('applier_form').submit();
   }
}

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;
            }
         }
      }
   }

}


// Runs when the body loads
function init()

{

   try

   {

      document.getElementById('logo_div').style.right = (screen.width / 2) - 320;



      if (document.getElementById('course_years_div'))

      {

            document.getElementById('course_years_div').style.left = (screen.width / 2) - 370;

      }



      // Try to position the news

      if (document.getElementById('news_title'))

      {

            init_parent_top = document.getElementById('news_title').offsetTop + document.getElementById('news_title').offsetHeight + 2;



            parent_top = init_parent_top;



      }



   }

   catch (e)

   {

      window.status = e.message;

   }



   //document.getElementById('main_body_div').style.visibility = 'visible';

}



// 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();

   }

}



// For every description that has a full version, it opens or closes it

function operate_description(id)

{

   var short = document.getElementById('description_' + id);

   var long = document.getElementById('full_description_' + id);



   if (short.style.display == '')

   {

      short.style.display = 'none';

      long.style.display = '';

   }

   else

   {

       short.style.display = '';

      long.style.display = 'none';

   }

}

$(document).ready(function() {
      $("a img").hover(function() {
         $(this).fadeTo("fast", 0.6);
      } ,
      function() {
         $(this).fadeTo("fast", 1);
      } );

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

      $(".outer_news_div").show("slow");
   }
);


                      var INIT_ABOUT_DIV_HEIGHT = '200px';
var more_text;
function operate_more(id, me)
{
   if (document.getElementById(id).style.overflow != 'hidden' && document.getElementById(id).style.overflow != '')
   {
      document.getElementById(id).style.height = INIT_ABOUT_DIV_HEIGHT;
      //document.getElementById(id).style.overflow = 'hidden';
      document.getElementById(me.id).innerHTML = more_text;
      move_news_up(id)  ;
   }
   else
   {
      more_text = document.getElementById(me.id).innerHTML;
      //document.getElementById(id).style.overflow = 'visible';
      document.getElementById(id).style.height = '';
      document.getElementById(me.id).innerHTML = 'סגור';
      move_news_down(id);
   }

}

function move_news_down()
{
   // Move news part
   if (typeof parent_top !== 'undefined')
   {

      parent_top = ($("#news_title").height() + parseInt(parent_top) + ($("#news_div").height() - parseInt(INIT_ABOUT_DIV_HEIGHT)))  + "px";

   }

}

function move_news_up()
{
   var jump = 1;
   // Move news part
   if (typeof parent_top !== 'undefined')
   {
      jump = parseInt(parent_top) - parseInt(init_parent_top);
      parent_top = parseInt(init_parent_top) + "px";

   }
   speed = jump;
   setTimeout("speed = default_speed;", 100);

}

$("document").ready(function () {

   $(".about_div span span:first").show();
      $("#more_div").click(
         function () {
            if ($(".about_div").css("height") != "420px")
            {
               $("#more_div img").attr("src", "/site/images/minus.png");
               $(".about_div").animate({height:"420"}, 500);
               $(".inner_about_div").css("overflow", "auto");
               move_news_down();
            }
            else
            {
               $("#more_div img").attr("src", "/site/images/plus.png");
              $(".about_div").animate({height:"200"}, 500);
               $(".inner_about_div").css("overflow", "hidden");
               move_news_up();
            }

         }
      )
   }
);


