
/*------------------------------------------------------------
# Author: Maxim Zetser
# Created: 28/8/11                                                                   
# Description: This file includes all JS scripts that should be loaded in every page of the Snunit site.   
------------------------------------------------------------*/

	$(document).ready(function(){
			$("#container").show();
			BuildBoxes();
			SetFloatHeight();
			SetFloatWidth();
			
			$("#form_search #q").focus(function(){
					$(this).attr("value","");							
				});
		});
	
	
	
	//////////////////////////Global Functions//////////////////////////////
	
	function BuildBoxes(){
			
			var top = '<div class="right top corner"></div><div class="top line"></div><div class="left top corner"></div><div class="clear"></div><div class="right line"></div>';
			
			var bottom = '<div class="left line"></div><div class="clear"></div><div class="right bottom corner"></div><div class="bottom line"></div><div class="left bottom corner"></div>';
			
			$(".box").each(function(i){
				if($(".box:eq("+i+")").children().length == 1){
					$(".box:eq("+i+")").prepend(top);
					$(".box:eq("+i+")").append(bottom);
				}					
			});			
		}
		
      function getCSSAttr(attr){		
			if(attr==undefined || isNaN(attr)) attr=0;
				return attr;
		}

	  function SetFloatHeight(){		  
		 $(".float_height").each(function(x){
										  
	  $(this).children (".left.line:first ,  .right.line:first ,  .content:first").height( $(this).children(" .content:first").height()+getCSSAttr(parseFloat($(this).children(".content:first").css("padding-bottom")))+getCSSAttr(parseFloat($(this).children(" .content:first").css("padding-top")))) 
									   });
		 
		  }
		  
	  function SetFloatWidth(){
		  $(".float_width").each(function(x){
		  $(this).children (".top.line:first ,  .bottom.line:first").width( calculateTotalWidth($(this))) ;	
		  $(this).children(".content:first").width($(this).children (" .top.line:first").width());
		  $(this).width(calculateTotalWidth($(this))+$(this).children(".left:first").width()+$(this).children(".right:first").width())
			  });
		}

	  function calculateTotalWidth(obj){
			  return parseFloat( $(obj).children(".content:first").width()) + getCSSAttr(parseFloat($(obj).children(".content:first").css("padding-right"))) + getCSSAttr(parseFloat($(obj).children(" .content:first").css("padding-left")))
		  
		}
		
	  function preSearchSubmit(){
			document.getElementById("form_search").submit();
			return true;
		}
		
	  function getParameterByName(name){
		name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
		var regexS = "[\\?&]" + name + "=([^&#]*)";
		var regex = new RegExp(regexS);
		var results = regex.exec(window.location.href);
		if(results == null)
		  return "";
		else
		  return decodeURIComponent(results[1].replace(/\+/g, " "));
	  }
		
	  //////////////////////////End of Global Functions//////////////////////////////
		
	function AddToFavorite(){
		 if (window.sidebar) { // Mozilla Firefox
				window.sidebar.addPanel("עמותת סנונית לקידום החינוך המתוקשב", "http://www.snunit.k12.il", "");
			}
			else if (window.external) { // IE
				window.external.AddFavorite("http://www.snunit.k12.il", "עמותת סנונית לקידום החינוך המתוקשב");
			}
			else if (window.opera && window.print) {
				window.external.AddFavorite("http://www.snunit.k12.il", "עמותת סנונית לקידום החינוך המתוקשב");
			}
			else {
				alert('not supported');
			}
		}	
		
