// JavaScript Document

$.fn.cycle.defaults.timeout = 6000;

function animate_poll(){

    $('.survey_image').each(

        function(){

            var o_width=$(this).attr("width");

            $(this).attr("width","0");

            $(this).animate({
                width:o_width+"px"
                },1500);

        });

}

$(function() {

    
    $("#nav li").hover(
        function()
        {
            /*$("ul",this).hide();*/
            $(this).addClass('over');
		/*var cr_item=$(this);
            $("ul",this).show("fast");*/
        //$("ul",this).stop().animate({opacity: 1},150);
        }
        ,
        function()
        {
			$(this).removeClass('over');
            //$("ul",this).stop().animate({opacity: 0},150);
            /*var cr_item=$(this);
            $("ul",this).hide("fast",function(){
				 if ($("ul",cr_item).is(":hidden")) {
                	$(cr_item).removeClass('over');
            	}*/
                //$(cr_item).removeClass('over');
           /* });
            if($("ul",this).length==0)
                $(cr_item).removeClass('over');*/
					
                    
        }
        );
    $("#search_text").focus(function(){
        if($("#search_text").val()=="Search here...")
            $("#search_text").val("");
    });
    $("#search_text").blur(function(){
        if($("#search_text").val()=="")
            $("#search_text").val("Search here...");
    });
	
	$("#search_text_ar").focus(function(){
			if($("#search_text_ar").val()=="نص البحث هنا...")
				$("#search_text_ar").val("");
		});
		$("#search_text_ar").blur(function(){
			if($("#search_text_ar").val()=="")
				$("#search_text_ar").val("نص البحث هنا...");
		});
    $("#search_btn").click(function(){
        $("#search_box form").submit();
    });
				
    $("#nl").focus(function(){
        if($("#nl").val()=="Enter your email..")
            $("#nl").val("");
    });
    $("#nl").blur(function(){
        if($("#nl").val()=="")
            $("#nl").val("Enter your email..");
    });
	
	$("#nl_ar").focus(function(){
			if($("#nl_ar").val()=="أدخل بريدك..")
				$("#nl_ar").val("");
		});
		$("#nl_ar").blur(function(){
			if($("#nl_ar").val()=="")
				$("#nl_ar").val("أدخل بريدك..");
		});
    $("#sign_up_nl").click(function(){
        $("#newsletter_form").submit();
    });
				
    $("#mem_login").click(
        function(){
            if ($("#mem_form").is(":hidden")) {
                $("#mem_form").slideDown("slow");
            } else {
                $("#mem_form").slideUp("slow");
            }
											  
        })
    $("#login").click(
        function(){
            $("#mem_login_form1").submit();
        }
						
        );
    $("#login2").click(
        function(){
            $("#mem_login_form2").submit();
        }

        );
    $("#add_new_industry").click(
        function(){
            var p = $(this);
            var position = p.position();
            $("#industry_form").css({"left": position.left,"top":position.top+170})
            $("#industry_form").show("slow");
            return false;
        });
    $("#close_industry").click(
        function(){$("#industry_form").hide("fast");
            return false;
        });
    $("#add_industry").click(
        function(){
            
            $.ajax({
                type:"post",
                cache: false,
                url: "add_industry",                
                data: "industry="+$("#industry").val(),
                success: function(msg){
                    
                            if(msg>0){
                                $("#add_new_industry").before('<label class="description" for="industry_id_'+msg+'">'+$("#industry").val()+'</label><input type="checkbox" name="industries[]" value="'+msg+'" checked="checked" id="industry_id_'+msg+'"  /><br/>');
                                msg="Recored added Successfully";
                            }
                            else
                                msg="Recored was not added Successfully";                        
                 alert( msg );
               }
              });
            //$("#industry_form").hide("fast");
            //return false;
        });
				
    function mycarousel_initCallback(carousel)
    {
        // Disable autoscrolling if the user clicks the prev or next button.
					
				
        // Pause autoscrolling if the user moves with the cursor over the clip.
        carousel.clip.hover(function() {
            carousel.stopAuto();
        }, function() {
            carousel.startAuto();
        });
    };
    $('#mycarousel').jcarousel({
        auto: 5,
        scroll:1,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
				

    //$('#nav li:eq(0) a').css('margin-top','2px');
    $('#news_ticker').cycle({
        fx:'slideY',
        speed: 1000,
        timeout: 4000,
        next:'#next_t',
        prev:'#prev_t',
        pause:1
    });
    $('#slides_t').cycle({
        fx:'fade',
        speed: 1000,
        timeout: 4000,
        pager:  '#slide_nav',
        pagerEvent:'mouseover',
        pauseOnPagerHover:true,
        pagerAnchorBuilder: function(idx, slide){
            return '#slide_nav li:eq(' + (idx) + ') ';
        }
    });

animate_poll();	

    var survey;

    $("input[type='submit'][name='survey']").bind('click',survey_click);

    function survey_click(){

        if($(this).val()=="عرض النتائج")

            survey="show_results";

        else

            survey="send_vote";

    }

    function submit_function(e){

        var option1;

        var survey_id;

        survey_id= $(this).children("input[name='survey_id']").val();

        //option1=$(this).children("ul").children("input[name='check_option'][checked='true']").val();
        option1=$("input[name='check_option']:checked").val();
        var sub_data="survey_id="+survey_id+"&check_option="+option1+"&survey="+survey;

        //alert(survey);

        $("#survey_overlay").fadeIn(300);

        $.ajax({

            type: "POST",

            contentType:"application/x-www-form-urlencoded; charset=windows-1256",

            scriptCharset:"windows-1256",

            dataType:"html",

            processData:false,

            type:"post",

            url: "survey/survey.php",

            data: sub_data,

            success: function(msg){

                //alert( "Data Saved: " + msg );

				 

                $("#serv .survey").remove();

                $("#serv #votes").remove();

                $('#serv').append(msg);

                $("#survey_overlay").fadeOut(800);

                //$('#serv').append(msg);

                //$(this).css("display","none");

                //alert(msg);

                animate_poll();

                $('.survey').bind('submit',submit_function);

                $("input[type='submit'][name='survey']").bind('click',survey_click);

            //alert(msg);

            }

        });

        //return false;

        return false;

			

    }

    $('.survey').bind('submit',submit_function);

    //$('#gallery a').lightBox({txtImage:"الصورة",txtOf:"من"});

    $('.search_btn').click(function(){

        $('.search_text_cont form').submit();

    });
});
