// JavaScript Document//Validator

var $STG=jQuery.noConflict();
$STG(document).ready(function () {
	$STG('.OPACE').hover(function () {
		$STG(this).fadeTo(0,0.8);
	},function(){
		$STG(this).fadeTo(0,1);
	});

	$STG('.HOVER').hover(function () {
		$STG(this).attr('src',$STG(this).attr('src').replace('.' + getEXT($STG(this).attr('src')),'_on.' + getEXT($STG(this).attr('src'))));
	},function(){
		$STG(this).attr('src',$STG(this).attr('src').replace('_on.' + getEXT($STG(this).attr('src')),'.' + getEXT($STG(this).attr('src'))));
	});
	
	var ReverseOpacityLevel=0.3;
	
	
	$STG('.ReverseOpacity').hover(function(){
		$STG(this).fadeTo(0,1,function(){
			$STG('.ReverseOpacity').not(this).fadeTo(0,ReverseOpacityLevel);
		});
	});
	
	$STG('#IconContainer').live('mouseleave',function(){
		$STG('.ReverseOpacity').fadeTo(400,1);
	});
	
	$STG('.Bouncy').click(function(){
		$STG(this).effect("bounce", { direction:'left',distance:10,times:2 }, 190);
	});
	
	$STG('.Subject').click(function(){
		var TD=$STG(this).parent();
		var TR=$STG(TD).parent();
		var TBL=$STG(TR).parent();
		var LI=$STG(TBL).parent();
		if($STG('.full_comment',LI).css('display')=='none'){
			$STG(this).addClass('On');
			$STG('img',this).attr('src','../images/blog/open.gif');
			$STG('.full_comment',LI).css('display','block');
			$STG(window).scrollTop(400);
		}
		else{
			$STG(this).removeClass('On');
			$STG('img',this).attr('src','../images/blog/closed.gif');
			$STG('.full_comment',LI).css('display','none');
		}
	});
	
	$STG('#showHide_Comments').click(function(){
		if($STG('#Comments').css('display')=='none'){
			$STG(this).addClass('On');
			$STG('img',this).attr('src','../images/blog/open.gif');
			$STG('#Comments').css('display','block');
			$STG(window).scrollTop(400);
		}
		else{
			$STG(this).removeClass('On');
			$STG('img',this).attr('src','../images/blog/closed.gif');
			$STG('#Comments').css('display','none');
		}
	});
		
	if($STG('#showAll_Comments').attr('rel')==0){
		$STG('#Comments').css('display','block');
		$STG('#Comments .full_comment').css('display','block');
		$STG('#Comments .Subject img').attr('src','../images/blog/open.gif');
		$STG('#Comments .Subject').addClass('On');
		
		$STG('#Comment_inner').css('display','block');
		$STG('.full_comment_inner').css('display','block');
		$STG('.Subject_inner img').attr('src','../images/blog/open.gif');
		$STG('.Subject_inner').addClass('On');
		$STG('#showAll_Comments').attr('rel',1);
		$STG('#showAll_Comments').html('סגירת כל התגובות');
		$STG('#showHide_Comments').addClass('On');
		$STG('img',$STG('#showHide_Comments')).attr('src','../images/blog/open.gif');
	}
	else{
		$STG('#Comments').css('display','none');
		$STG('#Comments .full_comment').css('display','none');
		$STG('#Comments .Subject img').attr('src','../images/blog/closed.gif');
		$STG('#Comments .Subject').removeClass('On');
		
		$STG('#Comment_inner').css('display','none');
		$STG('.full_comment_inner').css('display','none');
		$STG('.Subject_inner img').attr('src','../images/blog/clodes.gif');
		$STG('.Subject_inner').removeClass('On');
		$STG('#showAll_Comments').attr('rel',0);
		$STG('#showAll_Comments').html('פתיחת כל התגובות');
		$STG('#showHide_Comments').removeClass('On');
		$STG('img',$STG('#showHide_Comments')).attr('src','../images/blog/closed.gif');
	}
	
	
	$STG('#showAll_Comments').click(function(){
		if($STG(this).attr('rel')==0){
			$STG('#Comments').css('display','block');
			$STG('#Comments .full_comment').css('display','block');
			$STG('#Comments .Subject img').attr('src','../images/blog/open.gif');
			$STG('#Comments .Subject').addClass('On');
			
			$STG('#Comment_inner').css('display','block');
			$STG('.full_comment_inner').css('display','block');
			$STG('.Subject_inner img').attr('src','../images/blog/open.gif');
			$STG('.Subject_inner').addClass('On');
			$STG(this).attr('rel',1);
			$STG(this).html('סגירת כל התגובות');
			$STG(window).scrollTop(400);
		}
		else{
			$STG('#Comments').css('display','none');
			$STG('#Comments .full_comment').css('display','none');
			$STG('#Comments .Subject img').attr('src','../images/blog/closed.gif');
			$STG('#Comments .Subject').removeClass('On');
			
			$STG('#Comment_inner').css('display','none');
			$STG('.full_comment_inner').css('display','none');
			$STG('.Subject_inner img').attr('src','../images/blog/closed.gif');
			$STG('.Subject_inner').removeClass('On');
			$STG(this).attr('rel',0);
			$STG(this).html('פתיחת כל התגובות');
			$STG('#showHide_Comments').removeClass('On');
			$STG('img',$STG('#showHide_Comments')).attr('src','../images/blog/closed.gif');
		}
	});
	
	
	$STG('#main_comment_btn').click(function(){
		if($STG('#Add_Main_Comment').css('display')=='none'){
			$STG('#Add_Main_Comment').css('display','block');
			$STG(this).addClass('On');
			$STG(window).scrollTop(400);
		}
		else{
			$STG('#Add_Main_Comment').css('display','none');
			$STG(this).removeClass('On');
			//$STG('#Add_Main_Comment input').attr('value','');
			//$STG('#Add_Main_Comment textarea').attr('value','');
		}
	});
	
	$STG('.AddComment').click(function(){
		var Par=$STG(this).parent();
		Par=$STG(Par).parent();
		if($STG('#Add_Comment',Par).css('display')=='none'){
			$STG(this).addClass('On');
			$STG('#Add_Comment',Par).css('display','block');
			$STG(window).scrollTop($STG(window).height());
		}
		else{
			$STG(this).removeClass('On');
			$STG('#Add_Comment',Par).css('display','none');
			//$STG('#Add_Comment input',Par).attr('value','');
			//$STG('#Add_Comment textarea',Par).attr('value','');
		}
	});
	
	$STG('.Subject_inner').click(function(){
		var TD=$STG(this).parent();
		var TR=$STG(TD).parent();
		var TBL=$STG(TR).parent();
		var LI=$STG(TBL).parent();
		if($STG('.full_comment_inner',LI).css('display')=='none'){
			$STG(this).addClass('On');
			$STG('img',this).attr('src','../images/blog/open.gif');
			$STG('.full_comment_inner',LI).css('display','block');
		}
		else{
			$STG(this).removeClass('On');
			$STG('img',this).attr('src','../images/blog/closed.gif');
			$STG('.full_comment_inner',LI).css('display','none');
		}
	});
	
	setScrollBar();

});

function mycarousel_initCallback(carousel) {	
	jQuery('#LeftControl').bind('click', function() {
		clearInterval(T_Clock);
		jQuery(this).effect("bounce", { direction:'right',distance:10,times:2 }, 190);
		if(carousel.size()>4) carousel.next();
        return false;
    });
    jQuery('#RightControl').bind('click', function() {
		clearInterval(T_Clock);
		jQuery(this).effect("bounce", { direction:'left',distance:10,times:2 }, 190);
        if(carousel.size()>4) carousel.prev();
        return false;
    });
	
	jQuery("ul#Staff li div").click(function(){
		jQuery("ul#Staff li div").removeClass('Selected');
		jQuery(this).addClass('Selected');
		switchStaffPics(jQuery(this).attr('id'));
		var curP=jQuery(this).parent().get(0);
		var Xt=jQuery(curP).attr('jcarouselindex')-3;
		carousel.scroll(jQuery.jcarousel.intval(Xt));
		clearInterval(T_Clock);
	});
	
	jQuery("ul#Staff li div").removeClass('Selected');
	jQuery("ul#Staff li div#"+jcarousel_Items[0].id).addClass('Selected');
	switchStaffPics(jcarousel_Items[0].id);
	
};

function ClockMoveNext(){
	jQuery("#Staff").data('jcarousel').next();
	jQuery("ul#Staff li div").removeClass('Selected');
	jQuery("ul#Staff li div#"+jcarousel_Items[jQuery("#Staff").data('jcarousel').first-1].id).addClass('Selected');
	switchStaffPics(jcarousel_Items[jQuery("#Staff").data('jcarousel').first-1].id);
}

var jcarousel_Speed=400;
var jcarousel_Items=new Array();
var T_Clock;
jQuery(document).ready(function() {
	if(jQuery("#Staff").length>0){
		jcarousel_Items=jQuery("#Staff div");
		jQuery("#Staff").jcarousel({
			wrap: 'circular',
			scroll: 1,
			start: -2,
			animation: jcarousel_Speed,
			initCallback: mycarousel_initCallback,
			buttonNextHTML: null,
			buttonPrevHTML: null
		});
		//T_Clock=setInterval('ClockMoveNext()',4000);
	}
});
var wndo;
function setScrollBar(){
	if(document.getElementById('contentWarp')){
		if(document.getElementById('contentInner').scrollHeight>document.getElementById('contentInner').parentNode.offsetHeight){
			document.getElementById('scrollbar').style.visibility='visible';
			function init_dw_Scroll() {
				wndo = new dw_scrollObj('contentWarp', 'contentInner');
				wndo.setUpScrollbar("dragBar", "track", "v", 1, 1);
				wndo.setUpScrollControls('scrollbar');
			}
			if ( dw_scrollObj.isSupported() ) {
				init_dw_Scroll();
			}
		}
		else{
			document.getElementById('scrollbar').style.visibility='hidden';
			if(wndo) wndo.initScrollToVals(1, 0, 20);
		}
	}	
}

function getXMLObject(){
	var xmlHttp=false;
	try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP")}
	catch(e){try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")}
	catch(e2){xmlHttp=false}}
	if(!xmlHttp&&typeof XMLHttpRequest!='undefined'){xmlHttp=new XMLHttpRequest();}
	return xmlHttp;
}

function switchStaffPics(ID){
	var t=new Date();
	pageUlr='../AJAX/switchStaffPics.php';
	paramsString='id='+ID+'&time='+t.getTime();
	url =pageUlr;
	httpRequest = false;
	httpRequest=getXMLObject();
	httpRequest.onreadystatechange = function() {
	  if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			document.getElementById('MorePics').innerHTML=httpRequest.responseText;
			switchStaffData(ID);
			//alert(httpRequest.responseText);
		} else {
			//alert('There was a problem with the request.');
		}
	  }
	}
	httpRequest.open('GET', url+'?'+paramsString, true);
	httpRequest.send(null);
}

function switchStaffData(ID){
	var t=new Date();
	pageUlr='../AJAX/switchStaffData.php';
	paramsString='id='+ID+'&time='+t.getTime();
	url =pageUlr;
	httpRequest = false;
	httpRequest=getXMLObject();
	httpRequest.onreadystatechange = function() {
	  if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			document.getElementById('contentInner').innerHTML=httpRequest.responseText;
			setScrollBar();
		} else {
			//alert('There was a problem with the request.');
		}
	  }
	}
	httpRequest.open('GET', url+'?'+paramsString, true);
	httpRequest.send(null);
}


function IMG_ON(obj){
	obj.src=obj.src.replace('.' + getEXT(obj.src),'_on.' + getEXT(obj.src));
}
function IMG_OFF(obj){
	obj.src=obj.src.replace('_on.' + getEXT(obj.src),'.' + getEXT(obj.src));
}

function getEXT(str){
	str=str.split('.');
	ext=str[str.length -1];
	return ext;
}

function OPACITY_ON(obj){
	obj.className='opacity_80';
}
function OPACITY_OFF(obj){
	obj.className='';
}


function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    
	    return false
	 }

		 return true					
}

function checkComment(cont){
	if (cont.c_Name.value == "") {
		alert("נא להזין שם");
		cont.c_Name.focus();
		cont.c_Name.select();
		return false;
	}
	if (cont.c_Subject.value == "") {
		alert("נא להזין נושא");
		cont.c_Subject.focus();
		cont.c_Subject.select();
		return false;
	}
	return true;
}

function validForm(cont) {
	if (cont.Name.value == "") {
		alert("נא להזין שם");
		cont.Name.focus();
		cont.Name.select();
		return false;
	}
	if (cont.Mail.value == "" || !echeck(cont.Mail.value)) {
		alert("נא להזין כתובת מייל תקינה");
		cont.Mail.focus();
		cont.Mail.select();
		return false;
	}
	if (cont.Phone.value == "") {
		alert("נא להזין מספר טלפון");
		cont.Phone.focus();
		cont.Phone.select();
		return false;
	}
	return true;
}

function getAnchors(Source,Target){
	var Anchors=new Array();
	obj=document.getElementById(Source);
	Items=obj.getElementsByTagName('a');
	var c=0;
	for(var i=0; i<Items.length; i++){
		if(Items[i].name!='' && !Items[i].href){
			Anchors[c]=Items[i].name;
			c++;
		}
	}
	obj=document.getElementById(Target);
	for(var i=0; i<Anchors.length; i++){
		addElement(obj,Anchors[i]);
	}
}

function addElement(Obj,Name) {
  var ni = Obj;
  
  var newLi = document.createElement('li');
  ni.appendChild(newLi);
  
  var newEl = document.createElement('a');
  newEl.setAttribute('href','#'+Name);
  newEl.setAttribute('title',Name.replace('_',' '));
  newEl.innerHTML = Name.replace('_',' ');
  newLi.appendChild(newEl);
}
