var rnd_num =  '8876544';
jQuery(document).ready(function(){
	$('script,link').each(function(){
		return;
		var src= $(this).attr('src');
		var is_css= false;
		
		if($(this).is('link')){
			src = $(this).attr('href');
			is_css= true;
		}
		
		if(typeof src != 'undefined'){
			var attacher = '?';
			if(src.indexOf('?') > -1){
				attacher = '&';
			}
			src += attacher + 't=' + rnd_num;
			
			if(is_css){
				$(this).attr('href',src);
			}else{
				$(this).attr('src',src);
			}
		}
	});
	$('.fb-bar .close-fb').click(function(){
		$('.fb-bar').slideUp('slow',function(){
			$.ajax({
				'url':'?close_fb_bar=1'
			});
		});
	});
	$('.shine-links .link').click(function(){
		var pop_content_div;
		if($(this).is('.login')){
			pop_content_div = '.login_text';
		}else if($(this).is('.register')){
			pop_content_div = '.register_text';
		}else{
			return false;
		}
		
		$('.temp-shine').fadeOut('fast',function(){
			$(this).remove();
			
		});
		
		window.setTimeout(function(){
			pop_shine_box(pop_content_div);
		},500);
		return false;
	});
	
	$('.register-now').click(function(){
		$(document).scrollTop(0);
		$('.shine-links .link.login').click();	
	});
});

function pop_shine_box(pop_content_div){
	var pop = $('.shine-box').clone();
	if(pop_content_div == '.login_text'){
		pop.css('right','42px');
	}
	pop.appendTo('#mainstrip').find('.inner-div div').html($(pop_content_div).html());
	
	pop.find('.forgot-link').click(function(){
		$('.temp-shine').fadeOut('fast',function(){
			$(this).remove();
		});
		
		window.setTimeout(function(){
			pop_shine_box('.forgot_text');
		},500);
	});
	
	pop.addClass('temp-shine').fadeIn('slow').find('.close-x').click(function(){
		pop.fadeOut('fast',function(){
			$(this).remove();
		});
	});
	
	pop.find('form').submit(function(){
		pop.find('.error_area').html('').hide();
		var vals = $(this).serialize();
		var action = $(this).find('[name=action]').val();
		if(action=='register'){
			if(!($(this).find('[name=terms]').is(':checked'))){
				pop.find('.error_area').html('יש לאשר את תנאי השימוש.').show();
				return false;
			}
		}
		$.ajax({
			type:'post',
			data:vals,
			success:function(data){
				if(action =='login'){
					if(data.substr(0,1) == 1){
						document.location.reload();
						pop.fadeOut('slow');
					}else{
						pop.find('.error_area').html(data).fadeIn('slow');
					}
					return false;
				}else if(action == 'register'){
					pop.find('.inner-div div').html(data);
					pop.find('.resend-activation').click(function(){
						var email = $(this).attr('email');
						var user = $(this).attr('user');
						$.ajax({
							type:'post',
							data:{
								'is_ajax':'1',
								'action':'resend',
								'email':email,
								'user':user
							},
							success:function(data){
								pop.find('.inner-div div').html(data);
							}
						});
					});
				}else if(action == 'forgot'){
					if(data.substr(0,1) !='1'){//if error
						pop.find('.error_area').html(data).fadeIn('slow');
					}else{
						var msg = '<strong>';
						msg += 'נשלחה הודעה עם סיסמה חדשה לכתובת המייל שציינת, אנא בדקו את תיבת המייל והיכנסו עם הסיסמה החדשה לאתר.';
						pop.find('.inner-div div').html(msg);
					}
				}
			}
		});
		return false;

	});
	return false;
}