$(document).ready(function () {
  $('link[href=/umbraco/plugins/umbracoContour/css/defaultform.css]').remove();
  prepareFormFields();
});

//$(window).unload(function() {onSubmitContourForm( $('#contour').closest('form'));});

$(document).ready(function () {
  $('a#forgottenCode').click(function () {
    $('tr#hiddenRow').show();
  });
  if ($('.breadcrumbs').length == 0)
    $('.header').css('height', '111px');
});

function prepareFormFields() {

  $('#contour input[type=text]').each(function () {
    $(this).attr('title', $('label[for=' + $(this).attr('id') + ']').text())
    $('label[for=' + $(this).attr('id') + ']').addClass("inputText");
  });
  $('#contour textarea').each(function () {
    $(this).attr('title', $('label[for=' + $(this).attr('id') + ']').text())
    $('label[for=' + $(this).attr('id') + ']').addClass("inputText");
  });    
  prepareFormFieldsLabelInside();
}


function prepareFormFieldsLabelInside() {
  $('#contour textarea[title]').focus(function () { showHideInputValue($(this), 'focus') }).blur(function () { showHideInputValue($(this), 'blur') }).each(function () { showHideInputValue($(this), 'blur') });
  $('#contour input[type=text][title]').focus(function () { showHideInputValue($(this), 'focus') }).blur(function () { showHideInputValue($(this), 'blur') }).each(function () { showHideInputValue($(this), 'blur') });
}

function onSubmitContourForm(argFormObj) {
  $(argFormObj).find('#contour input[type=text]').each(function () {
    if ($(this).val() == $('label[for=' + $(this).attr('id') + ']').text())
      $(this).val("");
  });
}

function showHideInputValue(argObj, argStrType) {
  if (argStrType == 'focus' && $(argObj).val() == $(argObj).attr('title'))
    $(argObj).val('')
  else if ($(argObj).val() == "")
    $(argObj).val($(argObj).attr('title'))
}

$(function () {
  $('#s4').before('<div id="nav">').cycle({
    fx: 'fade',
    speed: 'slow',
    timeout: 0,
    pager: '#nav'
  });
});

$(function () {
  $('table pre code').not('#skip,#skip2').each(function () {
    eval($(this).text());
  });

  $('#s2').cycle({
    fx: 'fade',
    speed: 'slow',
    timeout: 0,
    next: '#next2',
    prev: '#prev2'
  });
});

function onBefore() {
  $('#output').html("Scrolling image:<br>" + this.src);
}

function onAfter() {
  $('#output').html("Scroll complete for:<br>" + this.src)
    .append('<h3>' + this.alt + '</h3>');
}

$.fn.cycle.defaults.speed = 3000;

$.fn.cycle.defaults.timeout = 1000;

$.fn.cycle.defaults.random = true;

$(function () {
  $('#fade').cycle();
});

$(document).ready(function () {

  $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
 $("ul.topnav li span").hover(function () {
      $(this).addClass("subhover"); //On hover over, add class "subhover"


      var subnav = $(this).parent().find("ul.subnav");
      var minheight = Math.max(subnav.height() - 89, 1);
      subnav.slideDown('fast').show(); //Drop down the subnav on click
      $('.container').css('min-height', minheight + 'px');
      $(this).parent().hover(function () {
      }, function () {
          $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
      });
  }, function () {  //On Hover Out
    $(this).removeClass("subhover"); //On hover out, remove class "subhover"
  });
});

$(window).bind("load", function () {
  $("div#basic").slideViewerPro({
    NovicellthumbsHeight: 71,
    NovicellthumbsWidth: 154,
    thumbs: 4    
  });
});
