﻿///<reference path="jquery-1.3.2-vsdoc.js" />

$(document).ready(function() {
    Cufon.replace('h1')('h2')('#topmenu a');

    $("#askAQuestion .textarea").example(WRITE_YOUR_QUESTION_HERE);
    $("#askAQuestion .input").example(YOUR_EMAIL);

    $("#ContactPage input[id*='SubjectTextBox']").example(SUBJECT);
    $("#ContactPage input[id*='NameTextBox']").example(NAME);
    $("#ContactPage input[id*='EmailTextBox']").example(EMAIL);
    $("#ContactPage input[id*='WebsiteTextBox']").example(WEBSITE);
    $("#ContactPage textarea[id*='MessageTextBox']").example(MESSAGE);

    $("#CaseStudiesPage .case a").click(function() {
        $.getJSON(FetchCaseStudyItemUrl, { id: $(this).attr("href").substring(1) }, function(result) {
            $("#CaseStudyLayer .title").text(result.Title);
            $("#CaseStudyLayer .body").html(result.Body);
            $("#CaseStudyLayer .client").html(result.Client);
            $("#CaseStudyLayer .branch").html(result.Branch);
            $("#CaseStudyLayer .project").html(result.Project);
            $("#CaseStudyLayer .medias").html(result.Medias);

            if (result.Images.length > 0) {
                $("#CaseStudyLayer .images .container").html("");
                for (var i = 0; i < result.Images.length; i++) {
                    $("#CaseStudyLayer .images .container").append("<img src=\"" + result.Images[i] + "\" alt=\"\"/>"); // width=\"318\" height=\"331\" 
                }
                $("#CaseStudyLayer .images, #CaseStudyLayer .images .container img:first").show();
                if (result.Images.length > 1) {
                    $("#CaseStudyLayer .paging span").text("1 / " + result.Images.length);
                    $("#CaseStudyLayer .paging").show();
                }
            }
            ToggleLightbox("CaseStudyLayer");
        });

        return false;
    });

    $("#CaseStudyLayer .close").click(function() {
        ToggleLightbox("CaseStudyLayer");
        $("#CaseStudyLayer .paging,#CaseStudyLayer .images").hide();
        return false;
    });

    $("#CaseStudyLayer .arrowLinkNext").live("click", function() {
        if (!$("#CaseStudyLayer .images .container img:last").is(":visible")) { // there is more
            var element = $("#CaseStudyLayer .images .container img:visible").hide().next().fadeIn().get(0);
            var currentIndex = $("#CaseStudyLayer .images .container img").index(element);
            $("#CaseStudyLayer .paging span").text((currentIndex + 1) + " / " + $("#CaseStudyLayer .images .container img").length);
        }
        return false;
    });

    $("#CaseStudyLayer .arrowLinkPrev").live("click", function() {
        if (!$("#CaseStudyLayer .images .container img:first").is(":visible")) { // there is more
            var element = $("#CaseStudyLayer .images .container img:visible").hide().prev().fadeIn().get(0);
            var currentIndex = $("#CaseStudyLayer .images .container img").index(element);
            $("#CaseStudyLayer .paging span").text((currentIndex + 1) + " / " + $("#CaseStudyLayer .images .container img").length);
        }
        return false;
    });

    if (location.hash) {
        $("#CaseStudiesPage .case a[href='" + location.hash + "']").click();
    }
});