window.focused = false;
window.onload = function(){
s('frm_search').txt_search.onfocus = function(){
if(this.value=='חיפוש באתר'){
this.value = '';
}}
s('frm_search').txt_search.onblur = function(){
if(this.value==''){
this.value = 'חיפוש באתר';
}}
s('frm_email').txt_email.onfocus = function(){
if(this.value=='- הזינו מייל -'){
this.value = '';
window.focused = true;
}}
s('frm_email').txt_email.onblur = function(){
if(this.value==''){
this.value = '- הזינו מייל -';
window.focused = false;
}}


}
document.onkeyup = function(e)
{

var event = e||window.event;
var keynum = event.keyCode;
if(keynum==13)
{
if(window.focused){
try{
add_email(s('frm_email'));
}catch(err){}}
return false;
}}
function check_search(frm){
if((frm.txt_search.value=='')||(frm.txt_search.value=='חיפוש באתר')){
alert('נא הכנס ערך לחיפוש');
frm.txt_search.focus();
return false;
}else{ 
return true;
}}
window.onload = function(){
function is_ie(){
if (navigator.userAgent.indexOf("MSIE")==-1){
return false;
}
else{
return true;
}}

is_ie = is_ie();

main_img_fadeouttime = 1000;
main_img_fadeintime = 1000;
function rand(n){

return (Math.floor(Math.random( )*n) + 1);
}
function rand_til_different(prev_rand, n){
new_rand = rand(n);
while(new_rand == prev_rand){
new_rand = rand(n);
}
return new_rand;
}


change_main_img = function(prev_rand){

clearTimeout(timer2);

new_rand = rand_til_different(prev_rand, 4); 

if(!is_ie){
$(".img_home_main").fadeOut(main_img_fadeouttime, function(){
$(this).attr("src", "/_media/images/home_obelisk_" + new_rand + ".jpg").load(function(){
$(this).fadeIn(main_img_fadeintime);
});
});
}else{
$(".img_home_main").fadeOut(main_img_fadeouttime, function(){
$(this).attr("src", "/_media/images/home_obelisk_" + new_rand + ".jpg");
var obj = $(this);
var img = obj[0];
img.onload = function(){
$(".img_home_main").fadeIn(main_img_fadeintime);
};
});
}
timer2 = setTimeout("change_main_img(" + new_rand + ")", 5000);
}


for(var i=1; i<5; i++){
if($("#img_"+i).attr('clientWidth') > 101){
$("#img_"+i).css('width', '100px');
}
if($("#img_"+i).attr('clientHeight') > 101){
$("#img_"+i).css('height', '100px');
}}

s('frm_search').txt_search.onfocus = function(){
this.value = '';
}
s('frm_search').txt_search.onblur = function(){
this.value = 'חיפוש באתר';
}
s('frm_email').txt_email.onfocus = function(){
if(this.value=='- הזינו מייל -'){
this.value = '';
}}
s('frm_email').txt_email.onblur = function(){
if(this.value==''){
this.value = '- הזינו מייל -';
}}

function max_img_dim(needed_width, needed_height, orig_width, orig_height){


if((needed_width>orig_width)&&(needed_height>orig_height)){

needed_width = orig_width;
needed_height = orig_height;

return Array(needed_width, needed_height);
}

if(needed_width < needed_height){
needed_height = needed_width * orig_height/orig_width;
}else if(needed_height < needed_width){
needed_width = needed_height * orig_width/orig_height;
}else{
needed_height = needed_width * orig_height/orig_width;
}

return Array(needed_width, needed_height);
}

var NUM_OF_PLACES = 4;
var timer;
var img_num = 1;
var img_dir = "_media/userfiles/customers/";
var timeout = 2300;
fadeouttime = 1000;
slidedowntime = 500;


change_pic = function(){
clearTimeout(timer);

file_name1 = pics_queue.shift();
pics_queue.push(file_name1);
file_name2 = pics_queue.shift();
pics_queue.push(file_name2);

$("#img_"+img_num).fadeOut(fadeouttime, function(){
if(is_ie){
changed = false;
$(this).onload = function(){
$(this).slideDown(slidedowntime);
changed = true;
};

$(this).attr('src',img_dir+file_name1);

if(changed == false&&is_ie){ 
$(this).slideDown(slidedowntime);
changed = true;
}}else{
$(this).load(function(){
$(this).slideDown(slidedowntime);
changed = true;
}).attr('src',img_dir+file_name1);
}

});


img_num++;
$("#img_"+img_num).fadeOut(fadeouttime, function(){
if(is_ie){
changed = false;
$(this).onload = function(){
$(this).slideDown(slidedowntime);
changed = true;
};

$(this).attr('src',img_dir+file_name2);

if(changed == false&&is_ie){ 
$(this).slideDown(slidedowntime);
changed = true;
}}else{
$(this).load(function(){
$(this).slideDown(slidedowntime);
changed = true;
}).attr('src',img_dir+file_name2);
}

});

img_num++;
if(img_num==5){
img_num = 1;
}

timer = setTimeout(change_pic, timeout);
}

change_pic();






prev_rand = $(".img_home_main").attr("src").split(".")[0];
prev_rand = prev_rand.charAt(prev_rand.length-1);

timer2 = setTimeout("change_main_img(" + prev_rand + ")", 5000);



}

