/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//function hide_green(){
//    $top = $('li.green div ul').css("top");
//    if ($top == '0px') {
//        $('li.green div ul').animate({
//            'top':"-210px"
//        }, 'fast');
//    }
//}
//function hide_sky_blue(){
//    $top = $('li.sky-blue div ul').css("top");
//    if ($top == '0px') {
//        $('li.sky-blue div ul').animate({
//            'top':"-210px"
//        }, 'fast');
//    }
//}
//function hide_dark_grey(){
//    $top = $('li.dark-grey div ul').css("top");
//    if ($top == '0px') {
//        $('li.dark-grey div ul').animate({
//            'top':"-210px"
//        }, 'fast');
//    }
//}
$(document).ready(function(){
    //    $('li.green span.clickable-item').click(function(){
    //        $top = $(this).parent().children('div').children('ul').css("top");
    //        if ($top == '-210px'){
    //            //$('#slideshow').cycle('stop');
    //            hide_sky_blue();
    //            hide_dark_grey();
    //            $(this).parent().children('div').children('ul').animate({
    //                'top':"0px"
    //            }, 'fast');
    //        }else if ($top == '0px') {
    //            $(this).parent().children('div').children('ul').animate({
    //                'top':"-210px"
    //            }, 'fast');
    //        }
    //    });
    //    $('li.sky-blue span.clickable-item').click(function(){
    //        $top = $(this).parent().children('div').children('ul').css("top");
    //        if ($top == '-210px'){
    //            hide_green();
    //            hide_dark_grey();
    //            $(this).parent().children('div').children('ul').animate({
    //                'top':"0px"
    //            }, 'fast');
    //        }else if ($top == '0px') {
    //            $(this).parent().children('div').children('ul').animate({
    //                'top':"-210px"
    //            }, 'fast');
    //        }
    //    });
    //    $('li.dark-grey span.clickable-item').click(function(){
    //        $top = $(this).parent().children('div').children('ul').css("top");
    //        if ($top == '-210px'){
    //            hide_green();
    //            hide_sky_blue();
    //            $(this).parent().children('div').children('ul').animate({
    //                'top':"0px"
    //            }, 'fast');
    //        }else if ($top == '0px') {
    //            $(this).parent().children('div').children('ul').animate({
    //                'top':"-210px"
    //            }, 'fast');
    //        }
    //    });



    $('li.subject>div').hide();
    $('li.subject').hover(
        function () {
            if($(this).index() == 0){
                $(this).addClass('green');
            }else if($(this).index() == 1){
                $(this).addClass('sky-blue');
            }
            $(this).children('div').show();
            $(this).children('div').children('ul').stop().animate({
                'top':"0px"
            }, 400);
        },
        function () {
            if($(this).index() == 0){
                $(this).removeClass('green');
            }else if($(this).index() == 1){
                $(this).removeClass('sky-blue');
            }
            $(this).children('div').children('ul').stop().animate({
                'top':"-210px"
            }, 400, function(){
                $(this).parent().hide();
            });
        }
        );


    $('#slideshow').cycle({
        fx:     'scrollHorz',
        speed:  4000,
        timeout: 500,
        startingSlide: 0
    });

    

    $("#clients").salah_slider({
        width:'680',
        parent_extra_hw:0,
        generate_slider:false,
        slides_cont:'#clients-logos div',
        next:'#next',
        prev:'#prev',
        children:'p',
        dir:'left',
        //                interval:6000,
        speed:1200,
        easing:'easeInOutSine',
        flexible:false
    });

    var current_list_slide=0;
    var list_total_width=0;
    $("#list-wrapper ul li").each(function(){
        list_total_width+=$(this).outerWidth();
    });
    if(list_total_width<$("#list-wrapper").outerWidth()){
        $("#services-next-arrow").hide();
    }
    $("#list-wrapper ul").css({
        'width':list_total_width
    });
            
    $("#services-next-arrow").click(function(){
        //                alert($("#list-wrapper ul li").eq(current_list_slide).html());
        //                alert(current_list_slide);
        var new_left=0;
        for(i=0;i<=current_list_slide;i++){
            if(list_total_width>$("#list-wrapper").outerWidth()-new_left){
                new_left-=$("#list-wrapper ul li").eq(i).outerWidth();
                $("#services-previous-arrow").removeClass('hidden');
                if(list_total_width<=$("#list-wrapper").outerWidth()-new_left){
                    $("#services-next-arrow").hide();                            
                    $("#services-previous-arrow").show();
                }
            }else{
                $("#services-next-arrow").hide();
                $("#services-previous-arrow").show();
                break;
            }
        }
        $("#list-wrapper ul").stop().animate({
            'left':new_left
        },400)
        current_list_slide++;
    });
    $("#services-previous-arrow").click(function(){
        //                alert($("#list-wrapper ul li").eq(current_list_slide).html());
        //                alert(current_list_slide);
        var new_left=0;
        for(i=0;i<=current_list_slide;i++){
            if(list_total_width<$("#list-wrapper").outerWidth()+new_left){
                new_left+=$("#list-wrapper ul li").eq(i).outerWidth();
                $("#services-previous-arrow").removeClass('hidden');
                if(list_total_width<=$("#list-wrapper").outerWidth()+new_left){
                    $("#services-previous-arrow").hide();                            
                    $("#services-next-arrow").show();                            
                }
            }else{
                $("#services-next-arrow").show();                            
                $("#services-previous-arrow").hide();
                break;
            }
        }
        $("#list-wrapper ul").stop().animate({
            'left':new_left
        },400)
        current_list_slide--;
    });
    //            $("#clients div p a").each(function(){
    //                var img=$(this).children('img');
    //                var img_width = $(img).width();
    //                $(img).css({'left':((170-img_width)/2)+'px','top':'-140px'});
    //            })
    //            
    $("#clients div p a img").hover(function(){
        $(this).stop().animate({
            'opacity':'0'
        },800,'easeOutElastic')
    },function(){
        $(this).stop().animate({
            'opacity':'100'
        },1500,'easeOutElastic')                
    })

    $('#services-summeries').children('div').hide();
    $('#services-summeries').children('div').first().show();

    $('#list-wrapper ul li').click(function(){
        $('#list-wrapper ul li span').each(function(){
            $(this).removeClass('active');
        });
        $(this).children('span').addClass('active');
        $item_index = $(this).index();
        $('.service-summery').each(function(){
            if ($(this).is(":visible")) {
                $(this).hide();
            }
        });
        $('.service-summery').each(function(){
            if ($(this).index() == $item_index) {
                $(this).show();
            }
        });
    });

    $('#close-map').click(function(){
        $('#map').fadeOut(300);
    });
    $('#open-map').click(function(){
        //            $('#map').css({'display':'block'});
        $('#map').fadeIn(400);
        initialize();
    });
    
})

