﻿$(document).ready(function() {
	// menu toggle = active,hover
	$('.menu a:not(.selected) img').hover(
	function(){
		var theSrc = $(this).attr('src').replace('-active','-hover');
		$(this).attr('src',theSrc);
	},
	function(){
		var theSrc = $(this).attr('src').replace('-hover','-active');
		$(this).attr('src',theSrc);
	});
	
	// add to favorites 
	$('.fav').jFav();
	
	// scroll init
	$('.scroll-box').jScrollPane({
	scrollbarWidth: 10,
	showArrows:false,
	scrollbarOnLeft:true
	});
		
	// opacity elm
	$('.opacity').css({'opacity':'0.75'});
	
	// news scroll
	$('#news-scroll').cycle({ 
		//fx: 'scrollUp',
		fx: 'fade',
		timeout: 7000,
		speed: 700,
		after:	onBefore
	});
	function onBefore(curr, next, opts) {
	$('#images-text li').hide();
    var index = $(this).parent().children().index(this);
	$('#images-text li:eq('+index+')').show();
	}
	// banner scroll
	if($('#advertise-text').length==0){
		$('#advertise-wrapper').cycle({ 
			fx: 'fade',
			timeout: 3000,
			speed: 700
		});
	}
	// send a friend modal
	$('.send-friend').click(function(){
		$('#send-friend-box').modal({
			overlayClose: true,
			onOpen: onOpenFunc,
			onClose: onCloseFunc
		});
	});
	
	function onOpenFunc(dialog){
		dialog.overlay.fadeIn('fast', function () {
			dialog.container.slideDown('fast', function () {
				dialog.data.slideDown('slow');
				$('.input-submit').click(function(){
					onCloseFunc(dialog);
				});
			});
		});
	}
	function onCloseFunc(dialog){
		dialog.data.slideUp('slow', function () {
			dialog.container.slideUp('fast', function () {
				dialog.overlay.fadeOut('fast', function () {
					$.modal.close(); // must call this!
				});
			});
		});
	}
	// fix PNG
	//$(document).pngFix();
	
	
	// Reset Font Size
	var originalFontSize = $('body').css('font-size');
		$(".resetFont").click(function(){
		$('body').css('font-size', originalFontSize);
	});
	// Increase Font Size
	$(".increaseFont").click(function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		$('body').css('font-size', newFontSize);
		return false;
	});
	// Decrease Font Size
	$(".decreaseFont").click(function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		$('body').css('font-size', newFontSize);
		return false;
	});

});
var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
function isEmail(str){
	return emailRe.test(str);
}
// add remove wishlist
function wishlist(act,postID){
		//alert(act+' '+postID);
		$act = act;
		$postID = postID;
		$.post("wishlist.php", { act: $act, postID: $postID },
  function(data){
    $("#act"+postID).text(data).show().fadeOut(2000); 
	if($act=='remove'){
		var t = setTimeout(function(){$("#post"+postID).slideUp()},2000);
	}
  });

}
function validateContact(){
	var email = $('#email');
	var fullname = $('#fullname');
	if(fullname.val()==''){
		alert('יש למלא שם מלא');
		fullname.focus();
		return false;
	}
	if(email.val()==''){
		alert('יש למלא דוא"ל');
		email.focus();
		return false;
	}
	if(!isEmail(email.val())){
		alert('כתובת דוא"ל אינה תקינה');
		email.focus();
		return false;
	}
	return true;
}
function validateRegister(){
	var email = $('#email');
	var firstName = $('#firstName');
	var lastName = $('#lastName');
	if(firstName.val()==''){
		alert('יש למלא שם פרטי');
		firstName.focus();
		return false;
	}
	if(lastName.val()==''){
		alert('יש למלא שם משפחה');
		lastName.focus();
		return false;
	}
	if(email.val()==''){
		alert('יש למלא דוא"ל');
		email.focus();
		return false;
	}
	if(!isEmail(email.val())){
		alert('כתובת דוא"ל אינה תקינה');
		email.focus();
		return false;
	}
	return true;
}
function validateRecommend(){
	var recommendField = $('#recommendField');
	var firstName = $('#firstName');
	var lastName = $('#lastName');
	var email = $('#email');
	if(firstName.val()==''){
		alert('יש למלא שם פרטי');
		firstName.focus();
		return false;
	}
	if(lastName.val()==''){
		alert('יש למלא שם משפחה');
		lastName.focus();
		return false;
	}
	if(email.val()==''){
		alert('יש למלא דוא"ל');
		email.focus();
		return false;
	}
	if(!isEmail(email.val())){
		alert('כתובת דוא"ל אינה תקינה');
		email.focus();
		return false;
	}
	if(recommendField.val()==''){
		alert('יש למלא המלצה');
		recommendField.focus();
		return false;
	}
	return true;
}
