// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Udviklet af:Rosendahls Strategisk Webbureau 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/* jQuery.clearField by Nicolaj Kirkgaard Nielsen
* Useage: $('input.text').clearField();
* Type of action is controlled by the class of the input field
* <input class="clear" value="Text to be cleared" /> - Normal clear field
* <input class="clear once" value="Text to be cleared" /> - Clear field, but don't return to previous value on blur
*/
(function ($) { $.fn.clearField = function (options) { var opts = $.extend({}, $.fn.clearField.defaults, options); return this.each(function () { var $this = $(this); var text_val = $.trim($this.val()); $this.data('clearField', { txt: text_val }).addClass('placeholder'); $this.focus(function () { if ($.trim($(this).val()) === $(this).data('clearField').txt) { $(this).val("").removeClass('placeholder'); } }).blur(function () { if ($.trim($(this).val()) === "" && (!$(this).hasClass('once') && opts.type != 'once')) { $(this).val($(this).data('clearField').txt).addClass('placeholder'); } }) }); }; $.fn.clearField.defaults = { type: 'auto' }; })(jQuery);

$(document).ready(function () {

  
    $('input.clear').clearField();

    // Email de-obfuscation e.g. "bill (at) mail dot com"
    $('a.mail').each(function () {
        var txt = $(this).text().replace(/\s\(at\)\s/, "@").replace(/\sdot\s/, ".");
        $(this).text(txt).attr('href', 'mailto:' + txt);
    });

    $(".videoplayer").colorbox({ close: "luk", iframe: true, innerWidth: 560, innerHeight: 340 });
    
    $('#references').ready(function () {

        //Hover effect on child elements that are not selected 
    $('.smallVideo').hover(function () {
          
          if (!$(this).hasClass('selected')) {
              $(this).addClass("hover");
          }
      },
      function () {
          $(this).removeClass("hover");
      }
    );
        //When page is loaded and no item is loaded, first child of videos will load

        var firstload = 1;
        if (firstload = 1 && $('body:has(#references)')) {
            console.log("inside if");
            firstload++;
            //Adding first video item to player
            $('#references .inner #message h1').html($('.smallVideo:first-child').find('.heading').html());
            $('#references .inner #message p.companyName').html($('.smallVideo:first-child').find('.companyName').html());
            $('#references .inner #message p.text').html($('.smallVideo:first-child').find('.hidden .text').html());

            //Creating youtubelink and special IE object 
            var youtubelink = "http://www.youtube.com/v/[X]?hd=1";
            var youtubelinkIE = "<OBJECT class=youtube-player width='560' height='340'><EMBED height='340' type=application/x-shockwave-flash width='560' src='http://www.youtube.com/v/[X]?hd=1' allowfullscreen='true' allowscriptaccess='always'></EMBED></OBJECT>";

            //Replacing X with youtube ID 
            youtubelink = youtubelink.replace('[X]', $('.smallVideo:first-child').find('a').metadata({ type: 'attr', name: 'data' }).youtube);
            youtubelinkIE = youtubelinkIE.replace('[X]', $('.smallVideo:first-child').find('a').metadata({ type: 'attr', name: 'data' }).youtube);


            if ($.browser.msie || parseFloat($.browser.version) < 7 || $.browser.webkit) {
                $('#references .inner #playerframe object').remove();
                $('#references .inner #playerframe').html(youtubelinkIE);

            } else {
                $('#references .inner #playerframe object embed').attr('src', youtubelink);
                $('#references .inner #playerframe object param[name=movie]').attr('value', youtubelink);
            }


            $('.smallVideo:first-child').addClass('selected');

        }

        $('#references .smallVideo').click(function () {

            if ($('.mid .smallVideo').hasClass('selected')) {
                $('.mid .smallVideo').removeClass('selected');
            }

            //Link for youtubeplayer with HD started
            var youtubelink = "http://www.youtube.com/v/[X]?hd=1";

            //special link for IE 
            var youtubelinkIE = "<OBJECT class=youtube-player width='560' height='340'><EMBED height='340' type=application/x-shockwave-flash width='560' src='http://www.youtube.com/v/[X]?hd=1' allowfullscreen='true' allowscriptaccess='always'></EMBED></OBJECT>";


            //Heading for the item
            var heading = $(this).find('.heading').html();

            //Companyname for the item
            var companyname = $(this).find('.companyName').html();

            //Text for the item
            var text = $(this).find('.hidden .text').html();

            //Id for the youtubeplayer
            var youtubeID = $(this).find('a').metadata({ type: 'attr', name: 'data' }).youtube;

            //replacing X with youtubeID in the youtubelink string
            youtubelink = youtubelink.replace("[X]", youtubeID);
            youtubelinkIE = youtubelinkIE.replace("[X]", youtubeID);
            //Posting to playerframe
            $('#references .inner #message h1').html(heading);
            $('#references .inner #message p.companyName').html(companyname);
            $('#references .inner #message p.text').html(text);

            if ($.browser.msie || parseFloat($.browser.version) < 7 || $.browser.webkit) {
                $('#references .inner #playerframe object').remove();
                $('#references .inner #playerframe').html(youtubelinkIE);

            } else {
                $(' #references .inner #playerframe object embed').attr('src', youtubelink);
                $('#references .inner #playerframe object param[name=movie]').attr('value', youtubelink);
            }



            //adding selected class to clicked target
            $(this).addClass('selected');

            return false;
        });
    });
});

