$(function() {

    /*----------------
	| תפריט
	|-----------------*/
    $("#menu li").hover(function(){
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    }, function(){
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    });
    
	$("#upper_link a, #admin_paging a, #footer a, #footer a img,").css({opacity:.6 })
	   .hover(
        function(){
			$(this).css({opacity: 1 })
        }, 
        function(){
			$(this).css({opacity:.6 })
        });
		
    /*----------------
	| גלריה
	|-----------------*/
    $("a[rel='gallery']").colorbox({
        current: "תמונה {current} מתוך {total}",
        opacity: .8
    });
	
    $(".center_box a").hover(
        function(){
            $(this).parent(".center_box").css({
                background:'#FFF',
                border: '1px solid #999999'
            })
        }, 
        function(){
            $(this).parent(".center_box").css({
                background:'#F0F0F0', 
                border: '1px solid #CCC'
            })
        });
	
    $(".center_box").css({
        background: '#FFF url(/images/loading.gif) no-repeat center center'
    });
	
    $("#images img").each(function(){
		
        $(this).onImagesLoaded(function(_img){ 
            $(_img).fadeIn('slow');
            $(_img).parents(".center_box").css({
                background:'#F0F0F0'
            });
        })
    });
	
	/*----------------
	| דפים
	|-----------------*/
	
	$("#story").jScrollPane({
		showArrows: true,
		verticalDragMinHeight: 60,
		verticalDragMaxHeight: 60,
		arrowScrollOnHover: true
	});
	
	/*----------------
	| Form
	|-----------------*/
	
	$(".button").css({opacity:.4});
	$(".button").hover(
        function(){
            $(this).css({opacity:1})
            },
        function(){
            $(this).css({opacity:.4})
            }
        );
	
	$(".input1, .input2").focus(function () {
        $(this).addClass("input_focus");
    });
    $(".input1, .input2").blur(function () {
        $(this).removeClass("input_focus");
    });
	
	
	// טופס קשר ---------------------

	 $("#contactform").submit(function(){
		 
		if($('#lang').val() == 'en'){
			var sending = 'Sending...'
    		var resend = 'Send';
   	 		var thakyou = '<p><strong>Thank you for contacting Meira Ohad Dori,<br /> Your details have been successfully sent.</strong></p>';
		}else{
			var sending = 'שולח...'
    		var resend = 'שלח';
   	 		var thakyou = '<p><strong>תודה שיצרת קשר עם מאירה אוהד דורי,<br />פרטיך ניקלטו ונשלחו בהצלחה.</strong></p>';
		}
		 
        $('#contactform .input1').removeClass("input_focus")
		$(".error").hide();
        var str = $(this).serialize();
        $.ajax({
            type: "POST",
            url: "/contact.common.php",
            data: str,
            beforeSend: function(){
                $("#send").val(sending);
                $("#send").attr("disabled", true);
            },
            success: function(msg){
                result = msg.substr(0, 3)
                message = msg.substr(3)
					
                if(result.substr(0,2) == 'OK'){
                    $("#contact").html(thakyou);
                }else{  
					$(".error:eq(0)").show();
                    $("#error").html(message);
                    $('#contactform .input1').each(function(index) {
                        if(result.charAt(index)=='1'){
							  $(".error:eq("+index+")").show() 
                              $(this).addClass("input_focus")
                        }
                    });
                }
            },
            complete: function(){
                if(result != 'OK'){
                    $("#send").val(resend);
                    $("#send").attr("disabled", false);
                }
            },
            error: function(xhr) {
                alert('Error!  Status = ' + xhr.status);
            }
        });
        return false;
    });
	
	 
	$(".presslink").colorbox({
        opacity: 	.8
    });


	/*----------------
	| ADMIN
	|-----------------*/
	
	$("#admin_list tr:has('td')").hover(
		function(){ $(this).addClass("list_over") }, 
		function(){ $(this).removeClass("list_over")} 
	);
	

});
