﻿$(document).ready(function () {
    //*** SERVICES LIST HOVERS
    $(".ServiceDisplay ol.servicesList li").each(function () {
        $(this).find(".item").addClass("pointer");
        $(this).hover(function () {
            $(this).find(".itemDetail").show();
        }, function () {
            $(this).find(".itemDetail").hide();
        });
    });

    //*** PROJECT LIST HOVERS
    $(".ProjectPage .FilterContainer ul li").hover(function () {
        $(this).addClass("hover");
    }, function () {
        $(this).removeClass("hover");
    });

    //$(".MainGalleryContainer ul").cycle();

    //*** PROJECT GALLERY
    // Project gallery thumbnail nav
    var div = $('.SubGalleryContainer'),
		ul = $('.SubGalleryContainer ul'),
    // unordered list's left margin
		ulPadding = 5;
    //Get menu width
    var divWidth = div.width();
    //Remove scrollbars
    div.css({ overflow: 'hidden' });
    //Find last image container
    var lastLi = ul.find('li:last-child');
    //When user move mouse over menu
    div.mousemove(function (e) {
        //As images are loaded ul width increases,
        //so we recalculate it each time
        var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
        var left = (e.pageX - div.offset().left) * (ulWidth - divWidth) / divWidth;
        div.scrollLeft(left);
    });

    // Cycle pager
    $.fn.cycle.updateActivePagerLink = function (pager, currSlideIndex) {
        $(pager).find('li').removeClass('active').filter('li:eq(' + currSlideIndex + ')').addClass('active');
    };

    // Media Gallery
    $(".MainGalleryContainer ul").cycle({
        fx: "scrollHorz",
        timeout: 4000,
        speed: 300,
        pager: ".SubGalleryContainer ul",
        pagerAnchorBuilder: function (idx, slide) {
            // return selector string for existing anchor 
            return '.SubGalleryContainer ul li:eq(' + idx + ') a';
        }
    });

    $(".SubGalleryContainer ul li").each(function () {
        $(this).addClass("pointer");
        $(this).find(".Caption").click(function () {
            $(this).prev().trigger("click");
        });
    });

    // Our Team image hovers
    $(".teamDisplay .teamList li a").hover(function () {
        $(this).addClass("hover");
    }, function () {
        $(this).removeClass("hover");
    });

    //*** SUBSCRIBE FORM
    $("#subscribeForm #name").val("Your Name");
    $("#subscribeForm #email").val("Your Email");
    $("#subscribeForm input.textbox").each(function () {
        var initVal = $(this).val();
        $(this).focus(function () {
            if ($(this).val() == initVal) {
                $(this).val("");
            }
        });
        $(this).blur(function () {
            if ($(this).val() == "") {
                $(this).val(initVal);
            }
        });
    });
	
	//*** 5P MODEL
	$("#essence #icons li").hover(function() {
		$(this).addClass("hover");
		$(this).find("img").animGrow();
	}, function() {
		$(this).removeClass("hover");
		if (!$(this).hasClass("active")) {
			$(this).find("img").animShrink();
		}
	});
	
	$("#fivePsDetail ul").cycle({
		fx: "scrollHorz",
        timeout: 4000,
        speed: 400	
	}).cycle("pause");
	
	$("#fivePsIcons li.communityValues div").addClass("active");
	$("#fivePsIcons a").click(function() {
		$("#fivePsIcons .active").removeClass("active");
		
		var itemClass = "." + $(this).parent().attr("class");
		itemClass = itemClass.replace("hover","");
		var detailIndex = $("#fivePsDetail ul").find(itemClass).index();
		$(this).parent().addClass("active");
		
		$("#essence #icons li:not(.active)").find("img").animShrink();
		
		$("#fivePsDetail ul").cycle(detailIndex);
		
		return false;
	});
});

function searchProject() {
    // Put on the search filter on the url
    var keyword = document.getElementById("txtSearch").value;
    window.location = "default.aspx?noflash=true&search=" + keyword;
}

$.fn.animGrow = function() {
	$(this).animate({
		"width" : "70px",
		"height" : "70px",
		"margin-top" : "5px",
		"margin-bottom" : "5px"	
	},200);
}

$.fn.animShrink = function() {
	$(this).animate({
		"width" : "45px",
		"height" : "45px",
		"margin-top" : "15px",
		"margin-bottom" : "15px"	
	},200);
}

// Belated PNG
DD_belatedPNG.fix('.logo, .imageType9, .Caption, #essences li a');
