// replace fonts (cufon)
Cufon.replace('#content h1', { fontFamily: 'UniversLight' });

var search_defaultText = '';

$(document).ready(function () {

    // set icons for links
    $("a[href^='http://']:not(:has(img)):not([href*='quintus.']):not([href*='visuals.'])").addClass('external');
    $("a[href^='https://']:not(:has(img))").addClass('external');

    $('a[href$=".doc"]').addClass('icon-doc').click(function () {
        window.open(this.href);
        return false;
    });
    $('a[href$=".pdf"]').addClass('icon-pdf').click(function () {
        window.open(this.href);
        return false;
    });
    $('a[href$=".xls"]').addClass('icon-xls').click(function () {
        window.open(this.href);
        return false;
    });

    // set target for external links   
    $('a.external').click(function () {      
        window.open(this.href);
        return false;
    });

    // replace submit buttons
    $('input[type$="submit"]').each(function (e) {
        var replacementLink = $('<a href="#" class="submit">' + $(this).attr('value') + '</a>');
        replacementLink.click(function (e) {
            e.preventDefault()
            $(this).prev().click();
        });

        $(this).css({ 'display': 'none' });
        $(this).after(replacementLink);
    });

    // init search box
    search_defaultText = $('#searchbox .input').val();

    $('#searchbox .input').focus(function () {
        $(this).removeClass('error');
        $(this).val('');
    });
    $('#searchbox .input').blur(function () {
        if ($(this).val() == '') { $(this).val(search_defaultText) };
    });
    $('#searchbox .submit').click(function (e) {
        e.preventDefault();
        doSearch();
    });
    $('#searchbox .input').keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            doSearch();
            return false;
        }
    });
});

function doSearch() {
  var search = $('#searchbox .input');
  if (search.val() != '' && search.val().toLowerCase() != search_defaultText.toLowerCase()) {
    document.location = $('#searchbox .submit').attr('href') + '?search=' + search.val();
  } else {
    search.addClass('error');
  }
}


// display YouTube video
function ShowPlayer(videoURL, videoWidth, videoHeight) {
  videoCode = videoURL.replace('http://www.youtube.com/watch?v=','');
  if (videoWidth == '') { videoWidth = '500'; }
  if (videoHeight == '') { videoHeight = '300'; }
  document.write('<p><object width="' + videoWidth + '" height="' + videoHeight + '"><param name="movie" value="http://www.youtube.com/v/' + videoCode + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + videoCode + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + videoWidth + '" height="' + videoHeight + '"></embed></object></p>');
}

