// JavaScript Document

/*function track_list(id) {
    new Ajax.Request('http://www.track-trace.com/my/track_list/'+ id, {
        asynchronous:false,
        evalScripts:true
    });
    document.trackform.submit();
}*/

function track_form(type) {
    $.ajax({
        type: "POST",
        url: 'http://www.track-trace.com/my/' + type,
        data: $('#myform').serialize(),
        success: function(msg){
            $('track_form_cont').html(msg);
            $('track_form_cont form').submit();
        }
    });
}

function animate_poll(){
    $('.survey_image').each(
        function(){
            var o_width=$(this).attr("width");
            $(this).attr("width","0");
            $(this).animate({
                width:o_width+"px"
            },1500);
        });
}


$(document).ready(function(){

    /*$("#track_btn").click(function(){
        track_form('track_form');
    })*/

    $("#main-menu li").hover(function(){
        $(this).addClass('over');
    },
    function(){
        $(this).removeClass('over');
    });
    
    $(".photo_gallery li a").fancybox({
        'transitionIn'	:	'elastic',
        'transitionOut'	:	'elastic',
        'speedIn'		:	600,
        'speedOut'		:	200,
        'overlayShow'	:	false
    });
	
    $("#contact_form a").click(function(){
        $("#contact_form").submit();
    });

    $('#contact_form input').focus(function(){
        if($(this).val()==$(this).attr('title'))
            $(this).val('');
    })
    $('#contact_form input').blur(function(){
        if($(this).val()=='')
            $(this).val($(this).attr('title'));
    })

    $("#login_btn").click(function(){
        if(!$(this).hasClass('open')){
            $(this).addClass("open");
            $("#membership-form").stop().animate({
                'top':'0px',
                height:'275px'
            },1000,'easeOutExpo');
        }else{
            $(this).removeClass("open");
            $("#membership-form").stop().animate({
                'top':'0px',
                height:'0px'
            },1000,'easeOutExpo');
        }
    });
    
    $("#login").click(
        function(){
            $("#mem_login_form1").submit();
        }

        );
    $("#login2").click(
        function(){
            $("#mem_login_form2").submit();
        });
	
    $("#salah_slider").salah_slider({
        "width":666,
        'easing':'easeOutElastic',
        'flexible':true
    });
    $("#services").salah_slider({
        "width":666,
        'easing':'easeOutElastic',
        'speed':2000,
        'flexible':true
    });
    
    /*$("#main_slider ul li div.page_content").each(function(){
        alert($(this).height());
    })*/
    $("#main_slider").css(
        'height',$("div.page_content").innerHeight()
        );
    
    /*$("#main_slider ul").css('height','auto');
    $("#slides-b-c").css('height','auto');*/
    /*$("#main_slider ul li").css('height','auto');*/
    
    $("#logos_slider").salah_slider({
        "width":240,
        'speed':1000,
        'next':'.next',
        'prev':'.prev',
        'slides_no':3,
        'dir':'left',
        children:'a'
    });
    
    $("#search_btn").click(function(){
        $(this).parent().submit();
    })
    
    //setTimeout("next_slide()",8000)
    $("input,textarea").focus(function(){
        if($(this).val()==$(this).attr("title"))
            $(this).val("");
    });
    
    $("input,textarea").blur(function(){
        if($(this).val()=="")
            $(this).val($(this).attr("title"));
    });
    
    $("#faqs a").click(function(){
          $("#faqs div.cont").slideUp("fast");
          var parent_c=$(this).parent().parent();
          $(parent_c).children(".cont").slideDown("fast");
          return false;
    });

    $(".menu_sitemap ul").slideUp("fast");
    $(".menu_sitemap a").click(function(){
        if($(this).next("ul").html()!=null){
            $(".menu_sitemap ul").not($(this).parents("ul")).slideUp("fast");
            $(this).next("ul").slideDown(700);
            return false;
        }
    });
    animate_poll();
    var survey;
    $("input[type='submit'][name='poll']").bind('click',survey_click);
    function survey_click(){
        if($(this).val()=="Vote")
            survey="send_vote";
        else
            survey="show_results";
    }
    var poll_btn="";
    function back_to_poll(){
        $(".poll_vote").show();
        $("#poll_results").remove();
        $(".survey_overlay").fadeOut(1200);
        return false;
    }
    $(".polls form .btns a").click(function(){
        if($(this).text()=="Vote"){
            //alert($(this).text());
            poll_btn="vote";
            $(this).parent().parent().submit();
            return false;
        }
        else if($(this).text()=="View result"){
            poll_btn="show_results";
            $(this).parent().parent().submit();
            return false;
        }
        else{
            return true;
        }        
    })
    
    function submit_function(e){
        var option1;
        var survey_id;
        var this_form=$(this);
        survey_id= $(":input[name='poll_id']",this_form).val();
        option1=$(":radio:checked",this_form).val();
        var sub_data="poll_id="+survey_id+"&check_option="+option1+"&ajax=1&poll="+poll_btn;
        var b_height=$(".survey_overlay").parent().height();
        $(".survey_overlay").css('height',b_height);
        $(".survey_overlay").fadeIn(300);
        $.ajax({
            contentType:"application/x-www-form-urlencoded; charset=utf-8",
            scriptCharset:"utf-8",
            dataType:"html",
            processData:false,
            cache:false,
            type:"post",
            url: $('.survey').attr("action"),
            data: sub_data,
            success: function(msg){
                if(msg=="please_select"){
                    alert("Please..Choose any Choice!");
                    $(".survey_overlay").fadeOut(800);
                    return false;
                }
                $(this_form).parent().hide();
                $('.polls').append(msg);
                $(".survey_overlay").fadeOut(800);
                animate_poll();
                //$('.survey').bind('submit',submit_function);
                $("#poll_results a").bind('click',back_to_poll);
                $("input[type='submit'][name='survey']").bind('click',survey_click);
            //alert(msg);
            },
            error:function(msg,text){
                alert(text);
            }
        });
        return false;
    }
    $('.survey').bind('submit',submit_function);
})
