
//Setting the CountDown Time
var countDownVal = '2012-03-30-08-0-00'; // '2011-11-11-01-45-0';

$(document).ready(function() {
    $('span.date').html(getDateString());
    $('.ruls-downloads li>a:first-child').addClass('box')
    $('.list04 li:nth-child(2n)').addClass('odd01');
    $('.list04 li:nth-child(2)').addClass('second');
    $('ul li:first-child').addClass('first-child');
    $('ul li:last-child').addClass('last-child');
    $('.listing-06 li:nth-child(3n)').addClass('third-child');
    $('.accordon>ul>li:even').addClass('even');
    $('.accordon>ul>li:odd').addClass('odd');
    $('.submenu>ul>li:even').addClass('even');
    $('.submenu>ul>li:odd').addClass('odd');
    $('.bord-members li:nth-child(3n)').addClass('third-child');
    $('.tab-block div:first-child').show();
	$('.box-tab-right>a.view-all:first-child').show();
    $('.ruls-downloads li:nth-child(4n)').addClass('fourth-child');
    $('.location-map-listing li:nth-child(2n)').addClass('second-child');
    $('.sponsers-list li:nth-child(4n)').addClass('fourth-child');
    $('.dir-logo li:nth-child(6n)').addClass('sixth-child');
	$('.titles li:even').addClass('even');
	$('.listing-13 li:even').addClass('even');
	$('.listing-14 li:even').addClass('even');
	$('.listing-05 li:odd').css('margin-left', '15px');
    $('.link-block div:last-child').css('width', '128px');
	$('ul.bord-members2 li:odd').addClass('odd');
	equalHeight($(".bord-members li"));
	equalHeight($(".ruls-downloads li"));
    equalHeight($(".list04 li"));
	equalHeight($("ul.bord-members2 li"));
	
	// Menu Hover Functions
	$('.menu>ul>li.last-child>a').css('padding', '11px 19px 11px 19px');
    $('.menu>ul>li.first-child>a').css('padding', '11px 19px 11px 19px');
	
	if($.browser.msie && parseInt($.browser.version, 10) == 7) {
   		$('.menu>ul>li>a').css('padding', '11px 17px 10px 17px');
		$('.menu>ul>li>a.active').css('padding', '11px 17px 10px 17px');
	}
		
    $('.menu>ul>li').hover(function() {
        if ($(this).children('div').length > 0) {

            $(this).children('div').show(); 
        }
        if ($(this).hasClass('first-child')) {
            $(this).removeClass('first-child');
            $(this).addClass('active-first');
        }
        if ($(this).hasClass('last-child')) {
            $(this).removeClass('last-child');
            $(this).addClass('active-last');
        }
        $(this).addClass('active');
    }, function() {
        if ($(this).hasClass('active-first')) {
            $(this).addClass('first-child');
            $(this).removeClass('active-first');
        }
        if ($(this).hasClass('active-last')) {
            $(this).addClass('last-child');
            $(this).removeClass('active-last');
        }
        $(this).removeClass('active');
        $(this).children('div').hide();
    });

    if ($('.menu li:first').hasClass('current')) {
        $('.menu li:first-child').removeClass('current');
        $('.menu li:first-child').addClass('current-first');
    }
    if ($('.menu li:last-child').hasClass('current')) {
        $('.menu li:last-child').removeClass('current');
        $('.menu li:last-child').addClass('current-last');
    }
	
	
	
	//submenu functions
    $('.submenu li a').next('ul').slideUp();
    $('.submenu li a').addClass('active');
    $('.submenu li a').click(function() {
        if ($(this).next('ul').length > 0) {
            $(this).next('ul').slideToggle();
            $(this).toggleClass('active');
        }
        //return false;
    });
	
	if ($('.submenu-left>ul>li a.current').length > 0) {
        $('.submenu-left>ul>li a.current').addClass('active');
        $('.submenu-left>ul>li a.current').next('ul').slideDown();
    }
	if ($('.submenu-left ul li.active').length> 0)
	{
		$('.submenu-left ul li.active').children('ul').slideDown();
		$('.submenu-left ul li.active>a').addClass('active');
	}

    //$('.submenu-left li a').next('ul').slideUp();
    //$('.submenu-left li a').removeClass('active');
    $('.submenu-left li a').click(function() {
        if ($(this).next('ul').length > 0) {
            $(this).next('ul').slideToggle();
            $(this).toggleClass('active');
        }
        //return false;
    });

    //footer menu align functions
    $('.link-block').masonry({
        itemSelector: '.footer-links',
        columnWidth: 185
    });

	//footer links click function
    $('.footer-links li a').click(function() {
        if ($(this).next('ul').length > 0) {
            $(this).next('ul').slideToggle(function() {
                $('.link-block').masonry({
                    itemSelector: '.footer-links',
                    columnWidth: 185
                });
            });
            $(this).toggleClass('active');
        }
    });
	
	//footer slogan hover
    $('.footer-slogan h2 ').css('opacity', '0.7');
    $('.footer-slogan h2 a').hover(function() {
        $(this).parent().css('opacity', '1');
    }, function() {
        $(this).parent().css('opacity', '0.7');
    });
	
	$('a.logo-link').hover(function(){
		$('.footer-slogan h2').css('opacity', '1');
	},function(){
		$('.footer-slogan h2').css('opacity', '0.7');	
	});
	
	
    //tabmenu click functions
    $('.block-01').show();
    $('.tab li a').click(function() {
        $('.tab li a').removeClass('active');
        $(this).toggleClass('active');
		$('.box-tab-right>a.view-all').hide();
        $('.tab-block>div').hide();
        $($('.tab-block>div')[$(this).parent().index()]).show();
		$($('.box-tab-right>a.view-all')[$(this).parent().index()]).show();
        return false;
    });
	
	 //tabmenu click functions for the driving permit
    $('.tab-block2>div').hide();
    $('.tab-block2>div:first-child').show();
    $('.tab2 li a').click(function() {
        $('.tab2 li a').removeClass('active');
        $(this).toggleClass('active');
        $('.tab-block2>div').hide();
        $($('.tab-block2>div')[$(this).parent().index()]).show();
        return false;
    });
	
	//Accordon functions
    $('.accordon li>div').hide();
    $('.accordon li.first-child').children('a').addClass('active');
    $('.accordon li.first-child').children().show();
    $('.accordon>ul>li>a').click(function() {
        $('.accordon li a').next().slideUp();
        if ($(this).next().css("display") == "none") {
            $(this).next().slideDown();
            $('.accordon li a').removeClass('active');
            $(this).addClass('active');
        }
        else {
            $(this).next().slideUp();
            $('.accordon li a').removeClass('active');
        }
        return false;
    });

    // Calendar Tab Click active class functions
    $('.calendar-box li a').click(function() {
        $('.calendar-box li a').removeClass('active');
        $(this).addClass('active');
        return false;
    });

    // View Map Click functions
    var pageHeight = $('.outer').height();
    var pageWidth = $('.outer').width();
    $('.overlay').css({ 'height': pageHeight, 'width': pageWidth });

	// Functions for loading Each map into a container
    $('a.map-01').click(function() {
        $('.overlay').show();
        $('.pop-container').show();
        $('.pop-holder').load('map-headquarters.html');
    });
    $('a.map-02').click(function() {
        $('.overlay').show();
        $('.pop-container').show();
        $('.pop-holder').load('map-sharjah.html');
    });
    $('a.map-03').click(function() {
        $('.overlay').show();
        $('.pop-container').show();
        $('.pop-holder').load('map-dubai.html');
    });
    $('a.pop-close').click(function() {
        $('.overlay').hide();
        $('.pop-holder').empty();
        $('.pop-container').hide();
    });
    $('.overlay').click(function() {
        $(this).hide();
        $('.pop-holder').empty();
        $('.pop-container').hide();
    });
	
	
	
//Scroll to Top Functions for each page 
	$('.innner-content').append('<a href="#" class="scroll-top">Scroll to Top</a>');
	if($('.innner-content').height()>1300)
	{
		$('a.scroll-top').show();
	}
	else{
		$('a.scroll-top').hide();
	}
		$('a.scroll-top').click(
	        function (e) {
            $('html, body').animate({scrollTop: '0px'}, 2000);
			return false;
	        }
	);
});

// Equal height functions for the li on driver pages
function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

////////////////////////// imagebox image align functions /////////////////////////////
window.onload = function(){
	$('.about-pic').each(function()
		{
			var imgHeight = $(this).children('img').height();
			var holderHeight = $(this).height();
			var differ = ((holderHeight-imgHeight)/2-9);
			$(this).children('img').css('margin-top',differ);
		});
	$('.imagebox').each(function()
		{
			var imgHeight = $(this).children('img').height();
			var holderHeight = $(this).height();
			var differ = ((holderHeight-imgHeight)/2-9);
			$(this).children('img').css('margin-top',differ);
		});
	$('.imagebox2').each(function()
		{
			var imgHeight = $(this).children('img').height();
			var holderHeight = $(this).height();
			var differ = ((holderHeight-imgHeight)/2-9);
			$(this).children('img').css('margin-top',differ);
		});
	$('.listing-11 li a.box').each(function()
	{
		var imgHeight = $(this).children('img').height();
		var holderHeight = $(this).height();
		var differ = ((holderHeight-imgHeight)/2);
		$(this).children('img').css('margin-top',differ);
	});
	$('li a.box').each(function()
	{
		var imgHeight = $(this).children('img').height();
		var holderHeight = $(this).height();
		var differ = ((holderHeight-imgHeight)/2);
		$(this).children('img').css('margin-top',differ);
	});
	$('.sponsers-list>li>span>a').each(function()
	{
		var imgHeight = $(this).children('img').height();
		var holderHeight = $(this).height();
		var differ = ((holderHeight-imgHeight)/2);
		$(this).children('img').css('margin-top',differ);
	});
	$('.country-flag').each(function()
	{
		var imgHeight = $(this).children('img').height();
		var holderHeight = $(this).height();
		var differ = ((holderHeight-imgHeight)/2);
		$(this).children('img').css('margin-top',differ);
	});
}

// Current Date on top of the page
function getDateString() {
    var thisDate = new Date();
    var weekArray = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
    var monthArray = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
    var weekIndex = thisDate.getDay();
    var weekName = weekArray[weekIndex];
    var monthName = monthArray[thisDate.getMonth()];
    var dateString = thisDate.getDate() + ' ' + weekName + ', ' + monthName + ' ' + thisDate.getFullYear();
    return dateString;
}

