﻿// JS file for the website content
/// <reference path="Microsoft/VeJavaScriptIntellisenseHelper.js" />

$(document).ready(function () {

    //Open external links in a new window
    $('a[href^="http://"], a[href^="https://"]')
    .attr({
        target: "_blank"
        //title: $(this).attr("title") + " - opens in a new window"
    });


    // Play the Showreel
    if ($("#video").length > 0) {
        playMovie();
    }

    if ($("#jquery_jplayer_xmas").length > 0) {
        playMusic();
    }


    if ($("ul.portfolio a li div p").length > 0) {
        //console.log("gonna ellipse the text to " + $("ul.portfolio a li div p").length + " elements.");
        $("ul.portfolio a li div p").each(function () {
            $(this).ThreeDots({ max_rows: 3 });
        });
    }


    //############ Update News Archives ###################
    $('#news-month-select,#news-year-select').live('change', function () {
        var form = $(this).closest('form');
        $.post($(form).attr('action'), form.serialize(), function (result) {
            $('#news-archive').html(result);
        });
        return false;
    });


});

function playMusic() {
    $("#jquery_jplayer_xmas").jPlayer({
        ready: function () {
            $(this).jPlayer("setMedia", {
                mp3: "/Content/sounds/xmas.mp3",
                oga: "/Content/sounds/xmas.ogg"
            }).jPlayer("play", 0);
            },
            swfPath: "/Scripts/jquery/",
            solution: "html, flash",
            supplied: "mp3, oga",
            backgroundColor: "transparent"
    });
}

function playMovie() {
    $("#jquery_jplayer_1").jPlayer({
        ready: function () {
            $(this).jPlayer("setMedia", {
                m4v: "/Content/movies/INK-Showreel.m4v",
                ogv: "/Content/movies/INK-Showreel.ogv"
            }).jPlayer("play");
        },
        ended: function (event) {
            $(this).jPlayer("play");
        },
        swfPath: "/Scripts/jquery",
        solution: "html, flash",
        supplied: "m4v, ogv",
        backgroundColor: '#fff',
        cssSelectorAncestor: '#jp_interface_1',
        cssSelector: {
            videoPlay: '.jp-video-play',
            play: '.jp-play',
            pause: '.jp-pause',
            stop: '.jp-stop',
            seekBar: '.jp-seek-bar',
            playBar: '.jp-play-bar',
            mute: '.jp-mute',
            unmute: '.jp-unmute',
            volumeBar: '.jp-volume-bar',
            volumeBarValue: '.jp-volume-bar-value',
            currentTime: '.jp-current-time',
            duration: '.jp-duration'
        }
    });
};


