﻿// JavaScript Document

$.fn.cycle.defaults.timeout = 6000;
function animate_poll(parent){
	$('.survey_image',parent).each(
		function(){
			var o_width=$(this).attr("width");
			$(this).attr("width","0");
			$(this).animate({width:o_width+"px"},1500);
	});
}

$(function () {

    $('#close-map').click(function () {
        $('#map').fadeOut(300);
    });
    $('#open-map').click(function () {
        //            $('#map').css({'display':'block'});
        $('#map').fadeIn(400);
        initialize();
    });


    $("#main_menu #menu > ul").addClass("menu");
    $("#main_menu #menu > ul > li:last").addClass("last");
    $("#main_menu #menu ul li a").wrapInner("<span></span>");
    $("#main_menu #menu ul li").each(function () {
        if ($("ul", this).length > 0)
            $(">a", this).addClass("parent");
    });
    


    $("#navigation > ul").addClass("nav");
    $("#navigation > ul > li > a").addClass("toplevel");
    $("#navigation > ul > li > ul > li:last").after("<li class=\"navround\"></li>");
    $("#navigation > ul > li > ul > li > ul > li:last").after("<li class=\"navround2\"></li>");

    $("#navigation > ul > li:last").addClass("last");
    $("#navigation #menu ul li a").wrapInner("<span></span>");
    $("#navigation #menu ul li").each(function () {
        if ($("ul", this).length > 0)
            $(">a", this).addClass("parent");
    });
    /* $("#nav li").hover(
    function()
    {
    $(this).addClass('over');
    //$("ul",this).stop().animate({opacity: 1},150);
    }
    ,
    function()
    {
    //$("ul",this).stop().animate({opacity: 0},150);
    $(this).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();
    });
    $("#submit_login").click(
    function () {
        $("#login_form").submit();
    });
    //$('#nav li:eq(0) a').css('margin-top','2px');

    $('#slides_t').cycle({ fx: 'scrollDown', easing: 'easeOutBack', speed: 500, timeout: 4000, pager: '#slide_nav',
        pagerEvent: 'click',
        pauseOnPagerHover: true,
        pagerAnchorBuilder: function (idx, slide) { return '#slide_nav li:eq(' + (idx) + ') '; }
    });

    animate_poll();
    var survey;
    $("a.back").bind('click', back_click);
    function survey_click() {
        if ($(this).val() == "ÃšÃ‘Ã– Ã‡Ã¡Ã¤ÃŠÃ‡Ã†ÃŒ")
            survey = "show_results";
        else
            survey = "send_vote";
    }
    $(".view_results,.vote_btn").click(function () {
        var parent = $(this).parent();
        var option1;
        var poll_id;
        var poll_op;
        if ($(this).html() == "View Results" || $(this).html() == "عرض النتائج")
            poll_op = "show_results";
        else
            poll_op = "send_vote";

        poll_id = $("input[name='poll_id']", parent).val();
        poll_option = $("input[name='option']:checked", parent).val();
        var sub_data = "poll_id=" + poll_id + "&option=" + poll_option + "&ajax=true&poll_op=" + poll_op;
        //$(parent).append('<div class="poll_overlay"></div>');
        $(".poll_overlay", parent).fadeOut(0).fadeIn(100);
        $.ajax({
            type: "POST",
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            scriptCharset: "utf-8",
            dataType: "html",
            processData: false,
            cache: false,
            url: "poll.aspx",
            data: sub_data,
            success: function (msg) {
                $(".poll_results", parent).append(msg);
                $("a.back").bind('click', back_click);
                $("ul,.view_results,.vote_btn", parent).fadeOut(1000, function () {
                    //$(".view_results,.vote_btn",parent).slideUp(1000);
                    $(".poll_results", parent).fadeIn(800);
                    $(".poll_overlay", parent).fadeOut(800);

                });
            }
        });
        return false;

    });
    function back_click() {
        var parent = $(this).parent();
        var super_parent = $(parent).parent();
        $(".poll_overlay", super_parent).fadeIn(800, function () {
            $("ul", super_parent).fadeIn(1000);
            $(".view_results", super_parent).fadeIn(1000);
            $(".vote_btn", super_parent).fadeIn(1000);
            $(".poll_results", super_parent).fadeOut(800).html("");
            $(".poll_overlay", super_parent).fadeOut(800);
        });
        return false;
    }

    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=utf-8",
            scriptCharset: "utf-8",
            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();

    });

    $('#more_curr').click(function () {
        $.blockUI({
            onBlock: function () {
                $.ajax({
                    contentType: "application/x-www-form-urlencoded; charset=utf-8",
                    scriptCharset: "utf-8",
                    dataType: "html",
                    processData: false,
                    cache: false,
                    type: "get",
                    url: "currencies.aspx",
                    success: function (msg) {
                        $('#currencies').html(msg);

                        $('.blockUI.blockMsg.blockPage ').animate({ height: ($('#currencies').height() + 10) + "px", width: ($('#currencies').width() + 10) + "px" });
                        $('#waiting').fadeOut("fast");
                        //$(".scroll").slideDown("fast");
                    },
                    error: function (msg, text) {
                        alert(msg + '\r\n' + text);
                    }
                });
            },
            message: $('#message'),
            css: {
                "height": $('#message').height() + "px", "width": $('#message').width() + "px",
                top: ($(window).height() - $('#message').height()) / 2 + 'px',
                left: ($(window).width() - $('#message').width()) / 2 + 'px',
                padding: "15px"
            }, centerY: true, centerX: true
        });

        $('.blockOverlay').click($.unblockUI);
        return false;
    });
});
