﻿// JavaScript Document


$(document).ready(function() {

    $('#news-slider').loopedSlider({
        container: ".newsCont",
        slides: ".slides",
        containerClick: false,
        slidespeed: 1500,
        fadespeed: 500,
        autoHeight: true,
        addPagination: true,
        pagination: "pagination",
        autoStart: 8000,
        restart: 8000
    });


    $('#fat-slider').loopedSlider({
        container: ".fatCont",
        slides: ".slides",
        containerClick: false,
        slidespeed: 1500,
        fadespeed: 1500,
        autoHeight: true,
        addPagination: true,
        pagination: "paginate",
        autoStart: 8000,
        restart: 8000
    });



    /* slider News Paging */
    $("ul.pagination:first").css({ float: 'right' }).before(("<span class='alignRight'>4/</span>"));
    $("ul.pagination:first li a").addClass("disableLink").css({ 'border': '0 solid #fff' });

    $("ul.pagination:last").css({ 'display': 'block', 'border-top': '1px solid #e6e6e6', 'margin-top': '10px', 'padding-top': '5px' });
    $("ul.pagination:last li").addClass("imgPaging");
    $("ul.pagination:last li:first").addClass("active");
    $("ul.pagination:last li a").html("");


    $("ul.paginate:first").css({ float: 'right' }).before(("<span class='alignRight'>4/</span>"));
    $("ul.paginate:first li a").addClass("disableLink").css({ 'border': '0 solid #fff' });




    /*var nwscount = $("imgPaging").size();*/
    /*$(".slides div img").each(function(){$(this).clone().appendTo(".imgPaging a")});*/

    /*for(i=0;i<3;i++){}*/
    $(".slides div img").each(function(index) {
        $(this).clone().appendTo(".imgPaging a:eq(" + index + ")");
    });

    $("imgPaging img").removeClass("alignRight, push-left-2");


    //On Hover Over
    function megaHoverOver() {
        $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
        (function($) {
            //Function to calculate total width of all ul's
            jQuery.fn.calcSubWidth = function() {
                rowWidth = 0;
                //Calculate row
                $(this).find("ul").each(function() { //for each ul...
                    rowWidth += $(this).width(); //Add each ul's width together
                });
            };
        })(jQuery);

        if ($(this).find(".row").length > 0) { //If row exists...

            var biggestRow = 0;

            $(this).find(".row").each(function() {	//for each row...
                $(this).calcSubWidth(); //Call function to calculate width of all ul's
                //Find biggest row
                if (rowWidth > biggestRow) {
                    biggestRow = rowWidth;
                }
            });

            $(this).find(".sub").css({ 'width': biggestRow }); //Set width
            $(this).find(".row:last").css({ 'margin': '0' });  //Kill last row's margin

        } else { //If row does not exist...

            $(this).calcSubWidth();  //Call function to calculate width of all ul's
            $(this).find(".sub").css({ 'width': rowWidth }); //Set Width


        }
    }
    //On Hover Out
    function megaHoverOut() {
        $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
            $(this).hide();  //after fading, hide it

        });
    }

    var config = {
        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
        interval: 100, // number = milliseconds for onMouseOver polling interval
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
        timeout: 100, // number = milliseconds delay before onMouseOut
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)
    };

    $("ul#atopnav li .sub").css({ 'opacity': '0' }); //Fade sub nav to 0 opacity on default
    $("ul#atopnav li").hoverIntent(config); //Trigger Hover intent with custom configurations

    var options;
    $(".searchFormsTtl").click(function() {
        $(".searchForms").slideToggle("slow");
    });
	$(".ContactTableHeaderLink").click(function() {
        $(".ContactTableInformation").slideToggle("slow");
    });


    $.superbox.settings = {
        boxId: "superbox", // Id attribute of the "superbox" element
        boxClasses: "", // Class of the "superbox" element
        overlayOpacity: .8, // Background opaqueness
        boxWidth: "600", // Default width of the box
        boxHeight: "400", // Default height of the box
        loadTxt: "جاري التحميل...", // Loading text
        closeTxt: "اغلاق", // "Close" button text
        prevTxt: "السابق", // "Previous" button text
        nextTxt: "اللاحق" // "Next" button text
    };
    $.superbox();



    $('.dtPicker1')
		.datePicker(
			{	
			    month:((new Date().getMonth())+2),
			    clickInput: true,
			    createButton: false,
			    renderCallback: function($td, thisDate, month, year) {
			        if (thisDate.isFriday()) {
			            $td.addClass('weekend');
			            $td.addClass('disabled');
			        }
			    }
			}
		)
		.bind('click',
			function() {
			    $(this).dpDisplay();
			    this.blur();
			    return false;
			}
		);
		

    /*$('.dtPicker1').DatePicker({
        format: 'm/d/Y',
        date: $('.dtPicker1').val(),
        current: $('.dtPicker1').val(),
        starts: 1,
        position: 'r',
        
        onChange: function(formated, dates) {
        $('.dtPicker1').val(formated);
        //$('.dtPicker1').DatePickerHide();
           
        }
    });*/

    $('.datepicker1')
        .datePicker(
			{
			    startDate:'01/01/2000',	
			    clickInput: true,
			    createButton: false
			    
			}
		)
		.bind('click',
			function() {
			    $(this).dpDisplay();
			    this.blur();
			    return false;
			}
		);
		
    
    $('.datepicker2')
        .datePicker(
			{
			    startDate:'01/01/2000',	
			    clickInput: true,
			    createButton: false
			    
			}
		)
		.bind('click',
			function() {
			    $(this).dpDisplay();
			    this.blur();
			    return false;
			}
		);



    $('div.expandable div.Khutbah_Content').expander({
        slicePoint: 1000,  // default is 100
        expandText: '[المزيد...]', // default is 'read more...'
        collapseTimer: 0, // re-collapses after 5 seconds; default is 0, so no re-collapsing
        userCollapseText: '[^]'  // default is '[collapse expanded text]'
    });


});

var min = 8;
var max = 18;
function increaseFontSize() {
    var p = document.getElementsByTagName('p');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != max) {
            s += 1;
        }
        p[i].style.fontSize = s + "px"
    }
}
function decreaseFontSize() {
    var p = document.getElementsByTagName('p');
    for (i = 0; i < p.length; i++) {
        if (p[i].style.fontSize) {
            var s = parseInt(p[i].style.fontSize.replace("px", ""));
        } else {
            var s = 12;
        }
        if (s != min) {
            s -= 1;
        }
        p[i].style.fontSize = s + "px"
    }
}


function showSummary(id) {
    var cID = "#summary" + id;

    activeState('#idea-menu', id)
    //$('.topicID').attr('value', id);
    $(".topicID").val($('.topicID option:contains(' + id + ')').val());
    //alert($(".topicID").val());
    
    //$('#idea-sum' + id).fadeIn("slow");
    //$('#idea-sum' + id).show();

    $('.jumaa-content').html($('#idea-sum' + id).html());

}


function activeState(id, r) {
    var activeCount = 0;
    $(id).find('a').each(function() {
        var rel = $(this).attr('rel');
        if (rel == r) {
            $(this).attr('class', "active");
            activeCount++;
        }
        else {
            $(this).attr('class', '');
        }
    });
}
