var p_id=0;
$('<img src="/images/first0.jpg">').load();
window.onload=function(){
	$('<img src="/images/first0.jpg">').load(function(){
		window.setTimeout(function(){$('<div id="f_img"><img src="/images/first0.jpg"></div>').prependTo('#first').animate({opacity:0},0).animate({opacity:1,left:0},'slow',function(){
			$('#f_catalog').animate({top:465},300);
		})},100);
		
	});
	
	window.setTimeout('chpic(1)',3500);
}

function chpic(e){

	$('<img src="/images/first'+e+'.jpg">').load(function(){
		$('#f_img').fadeOut(function(){
			$(this).html('<img src="/images/first'+e+'.jpg">').fadeIn(function(){
				e++;
				e = e>6 ? 0 : e;
				window.setTimeout('chpic('+e+')',4000);
			});
		})
	});
		
		

}

$(function(){
	$('input').each(function(){$(this).attr('oval',$(this).attr('value'))}).focus(function(){if($(this).val()==$(this).attr('oval')){$(this).val('');}}).blur(function(){if($(this).val()==''){$(this).val($(this).attr('oval'));}});
	
	$('#menu div').last().css('background','none');
	$('.fcont').last().css('border','none')
	$('.custs').hover(
		function(){$(this).children('.c0').animate({top:'-=4'},'fast');$(this).children('.c0').animate({top:'+=4'},'fast');},
		function(){$(this).children('.c1').animate({top:'+=4'},'fast');$(this).children('.c1').animate({top:'-=4'},'fast');}
	);
	$('.r_title').not('.r_title_1').click(function(){
		id=$(this).attr('id');
		if($('#i'+id).is(':visible'))
		{
			$('#i'+id).slideUp('def',function(){$('#r_arr').css('top',$('.r_title_1').position().top+'px');});
		}else{
			$('.r_cont').not('#i'+id+', .r_cont_1').slideUp('def',function(){
				$('#i'+id).slideDown('def',function(){$('#r_arr').css('top',$('.r_title_1').position().top+'px');});
			});
		}
	});
	if($('.r_title_1').length){$('#r_arr').css('top',$('.r_title_1').position().top+'px');}else{$('#r_arr').hide();}
	if(($('#main').height()-200)<$('#right').height()){$('#main').height($('#right').height()+200)}
	
	$('.pbox').hover(
		function(){
			$(this).children('.ptrans').animate({bottom:'-=4'},'fast');
			$(this).children('.pmask, .pimg, .ptitle').animate({top:'-=4'},'fast');
		},
		function(){
			$(this).children('.ptrans').animate({bottom:'+=4'},'fast');
			$(this).children('.pmask, .pimg, .ptitle').animate({top:'+=4'},'fast');
		}
	).not('.plink').click(function(){pbig($(this).attr('id'));});
	$('.plink').click(function(){window.self.location.href='/'+$('.r_title_1').html().replace(/ /g,'+')+'/'+$(this).children('.ptitle').html().replace(/ /g,'+')+'/'+$(this).attr('id')})
	$('#p_close').click(function(){closePbig()})
	
	$('#p_right,#p_left').click(function(){chpbig($(this))});
	$('#mcat').attr('href',$('.fc_item a').eq(0).attr('href'))
	
})

function chpbig(t){
	d=t.attr('id')=='p_right' ? 1 : -1 ;
	ind=$('#'+p_id).index();
	tnext=$('.pbox').eq(ind+d);
	p_id=tnext.attr('id');
	$('<img src="/thumbs.php?w=550&s=images/uploads/'+tnext.attr('id')+'.jpg" style="height:360px">').load();
	$('#p_img').fadeOut(function(){$(this).html('<img src="/thumbs.php?w=550&s=images/uploads/'+tnext.attr('id')+'.jpg" style="height:310px">').fadeIn()});
	$('#p_title').html(tnext.children('.ptitle').html());
	$('#p_body').html(tnext.children('.pbody').html());
	
	ind=$('#'+p_id).index();
	if(ind==0){$('#p_left').hide()}else{$('#p_left').show()}
	if($('.pbox').eq(ind+1).length){$('#p_right').show()}else{$('#p_right').hide()}	
};

function pbig(id){
		p_id=id;
		$('#p_title').html($('#'+id).children('.ptitle').html());
		$('#p_body').html($('#'+id).children('.pbody').html());
		$('#p_img').html('<img src="/thumbs.php?w=550&s=images/uploads/'+id+'.jpg" style="height:310px">');
		
		ind=$('#'+id).index();
		if(ind==0){$('#p_left').hide()}else{$('#p_left').show()}
		if($('.pbox').eq(ind+1).length){$('#p_right').show()}else{$('#p_right').hide()}
		
		dwidth=$(document).width();
		dheight=$(document).height();
		$('<div id="scover">').appendTo('body').css({'background':'black','position':'absolute','top':'0px','left':'0px','z-index':'999999998'}).width(dwidth).height(dheight)
		.animate({opacity:0},0,function(){
			$(this).animate({opacity:0.87},'def',function(){
			
				$('#sbox').css({'left':function(){return ($('.wrapper').eq(0).offset().left+105)+'px'}}).slideDown();
			
			});
		})
		.click(function(){closePbig();});
}
function closePbig(){
	$('#sbox').stop().hide();
	$('#scover').stop().fadeOut('fast',function(){$(this).remove()})
}

function send(){ 
	var strData='';
	var frm='cfrm';
	$('#'+frm+' input, #'+frm+' textarea').each(function(){strData=strData+'&'+$(this).attr('name')+'='+$(this).val();});
	
	$.ajax({
		url:'/getlead.php',
		type:'POST',
		async:false,
		cache:false,
		dataType:'html',
		data:'cha=מאובטח'+strData,
		success:function(){ $('#cfrm').html('תודה על פנייתך.<br>אנו ניצור עמך קשר בהקדם');}
	});
}
