/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



$(function(){
    $('#s3').cycle({
        fx:'custom',
        sync: 1,
        cssBefore: {
            top:0,
            left: -582,
            display: 'block',
            'background':'none'
        },
        cssAfter: {
            'background':'none'
        },
        animIn:{
            left:0
        },
        animOut:{
            top: 260
        },
        delay: -1000 ,
        fx: 'fade',
        //easing:'easeInBack',
        pager:'#nav',
        pagerEvent:'mouseover',
        pauseOnPagerHover:true,
        pagerAnchorBuilder: function(idx, slide){
            return '#nav li:eq(' + (idx) + ') a';
        }
    });
    $('#photo_gallery #photos_list a').lightBox({
        txtImage:"الصورة",
        txtOf:"من"
    });
    $('#photos_list li.p a').lightBox({
        txtImage:"الصورة",
        txtOf:"من"
    });
    $("#tabs").tabs();
    jQuery('ul.superfish').superfish();
    function animate_poll(){
        $('.survey_image').each(
            function(){
                var o_width=$(this).attr("width");
                $(this).attr("width","0");
                $(this).animate({
                    width:o_width+"px"
                },1500);
            });
    }
    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(".poll_option").children("input[name='check_option'][checked='true']").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);
    $('a.media').media({
        width: 248,
        height: 166,
        autoplay: false,
        bgColor:"transparent",
        attrs:{wmode:'transparent'},
        params:{
            wmode:'transparent'
        }
    });
    $('a.wide_video').media({
        width: 510,
        height: 280,
        autoplay: true,
        bgColor:"transparent"
    });
});
