$(document).ready(function () {
    $(".contacthold ul li:first").addClass("selected");
    $(".contact div:first").addClass("show");

    // var div = 1;
    // $('ul.parent li').each(function (index) {
    //     var place = (index + 1) * 2 + $(this).find("ul > li").size()        
    //     alert(div);
    //     if (place > 10 * div) {
    //         div++;
    //         $(this).after('</ul><ul class="parent">')
    //     }
    // });

    $(".contacthold ul li a").click(function () {
        $(".contacthold ul li").removeClass("selected");
        $(this).parent().addClass("selected");
        $(".contact div").removeClass("show");
        var tabindex = $(".contacthold ul li a").index($(this));
        $(".contact div").eq(tabindex).addClass("show");
        return false;
    });

    $("li.sub a.par").mouseover(function () {
        $(this).addClass("hover");
        $(this).parent().find('ul').slideDown("fast");
    });
    $("li.sub").mouseleave(function () {
        $(this).find('a').removeClass("hover");
        $(this).find('ul').slideUp("fast");
    });
    $(".parentbg").mouseover(function () {
        $(this).parent().addClass(".blockhover");
    });
    $(".parentbg").mouseleave(function () {
        $(this).parent().removeClass(".blockhover");
    });
    $(".parentbg").click(function () {
        var attr = $(this).find('a').attr('title');
        if (attr.length==0){
               $(this).find('a').fancybox({ padding:0,width:620,height:520}).trigger('click');   
        }else{          
              window.location = $(this).find('a').attr('href');    
        }
    });

    //Contact Form Functionality
     $('.popup input[type="text"],.popup textarea').addClass("idleField");
     $('.popup input[type="text"],.popup textarea').focus(function () {
              $(this).removeClass("idleField").addClass("focusField");
     });
     $('.popup input[type="text"],.popup textarea').blur(function () {
              $(this).removeClass("focusField").addClass("idleField");
     });

    $(".dropdown h3").mouseover(function () {
        $(this).addClass("hover");
        $(this).parent().find('ul').slideDown("fast");
    });
    $(".dropdown").mouseleave(function () {
        $(this).find('a').removeClass("hover");
        $(this).find('ul').slideUp("fast");
    });
    $(".dropdown a").click(function () {
        var url = $(this).attr('title') + '.aspx';
        $('.popblock').empty();
        $.get(url, function (data) {
            $('.popblock').html(data);
        });
        $(".popblock").show();
        $(".payme").hide();
        $(".quotes").hide();
        $("a.closebtn").live('click', function () {
            $(".popblock").hide();
            $(".payme").show();
            $(".quotes").show();
        });
    });

    $("li.sub li:last-child").addClass("end");
    $(".dropdown li:last-child").addClass("end");
    $(".worldmap ul").liScroll({ travelocity: 0.12 });
    $(".fancy,.iframe").fancybox({padding:0,width:620,height:520});

    //$('.staff li:nth-child(4n)').addClass('noright');

    setStaff();
    function setStaff() {
        $('.staff li').mouseover(function () {
            $(this).find('.dis').fadeIn();
        });
        $('.staff li').mouseleave(function () {
            $(this).find('.dis').fadeOut();
        });
        $('.staff li').click(function () {
            $(this).find('.dis').hide(); //To Fix Fancybox watermarking issue
            $(this).find('a').trigger('click');
        });
    }




    // get the action filter option item on page load
    var $filterType = $('.buttons li.select').attr('class');

    // get and assign the ourHolder element to the
    // $holder varible for use later
    var $holder = $('ul.staff');

    // clone all items within the pre-assigned $holder element
    var $data = $holder.clone();

    // attempt to call Quicksand when a filter option
    // item is clicked
    $('.buttons li').click(function (e) {
        //$data.find('li:nth-child(4n)').removeClass('noright');
        // reset the active class on all the buttons
        $('.buttons li').removeClass('select');

        // assign the class of the clicked filter option
        // element to our $filterType variable
        var $filterType = $(this).attr('data-id');
        $(this).addClass('select');
        if ($filterType == 'all') {
            // assign all li items to the $filteredData var when
            // the 'All' filter option is clicked
            var $filteredData = $data.find('li');
        }
        else {
            // find all li elements that have our required $filterType
            // values for the data-type element
            var $filteredData = $data.find('li[data-type=' + $filterType + ']');
        }

        // call quicksand and assign transition parameters
        $holder.quicksand($filteredData, {
            duration: 400,
            easing: 'easeInOutQuad'
        }, function () { // callback function
            setStaff();
            $(".staff .iframe").fancybox({padding:0,width:620,height:520});
        });
        //$('.staff li:nth-child(4n)').addClass('noright');
        return false;
    });



});
			

        $.getJSON("/homepage-slider-images.aspx", function(data) {
			$(document).ready(function(){
				$(".slideshow").agile_carousel({
					carousel_data: data,
					carousel_outer_height: 360,
					carousel_height: 360,
					slide_height: 360,
					carousel_outer_width: 630,
					slide_width: 630,
					transition_time: 300,
					timer: 4000,
					continuous_scrolling: true,
					control_set_1: "numbered_buttons,previous_button,next_button"
					});
				});
			});


function contactFormSubmit(officeId, yourName, yourPhone, yourEmail,yourMessage) {

    AjaxService.EmailContact(officeId, yourName, yourPhone, yourEmail, yourMessage, function (result) {

		$("#success").show();
		$("#form").hide();


    }, function (r) {
            alert(r);
    });
}
