﻿$(document).ready( function() {
 
  var DOMAIN = 'Files/System/anm/';
 
 
 
/*
  Table special styles
*/
$('.anm-table th:nth-child(1)').css({
  'background-image' : 'url(' + DOMAIN + 'layout/table-orange-grad.png)',
  'background-color' : '#F79010'
})
 
 
 
$('.anm-table td:nth-child(1)').css({
  'border-bottom' : '1px solid #FCCA8D'
});
 
 
 
/*
  Athlete list filter
*/
$('#clube-list-select').change(function () {
  window.location = $(this).val();
});
$('#clube-list-select option').each (function () {
  if('/Default.aspx'+window.location.search == $(this).val()) $(this).attr('selected','selected');
});
/*
  Search Box js
*/
 
  function onFocus (e) {
    if($(this).data('string') === undefined || $(this).val() == $(this).data('string')) {
      $(this).data('string',$(this).val());
      $(this).val('');
    }
  }
 
  function onBlur (e) {
    if($(this).val() == '') {
      $(this).val($(this).data('string'));
    }
  }
  
  //$('#search-input').focus(onFocus);
  //$('#search-input').blur(onBlur);
  
  $('#search-button').parent('form').submit(function (e) {  
    e.preventDefault();
    sValue = $(this).children('#search-input').val();    
    if(sValue == 'pesquisa...' || sValue == '') {
      alert('O campo de pesquisa encontra-se vazio.');
      return false;
    } else {
      $(this).unbind('submit');
      $(this).submit();
    }
  });
  
 
  /*
   special style for breadcrumbs
  */
  var legend = $('span.Legend'),
  lContent = new String(legend.html());
 
  legend.html(lContent.substring(5));
  /*legend.children('a:last').css('color','#F16F21'); */
 
 
  /*
    Forces selected anchors to open link in new window
  */
  $('.footer-logos ul li a').bind('click',function (e) {
    e.preventDefault();
    window.open($(this).attr('href'));
  });
 
  /*
    Fixes css for 2nd image of the home page newslist
  */
 
  $('div.left-col div.news-list div.news-item div.item-image').eq(1).css({
    'top'   : '167px',
    'left'  : '41px',
    'width' : '98px',
    'height': '98px'
  });
 
  /*
   fixes background
  */
 
  var windowHeight = function () {
    if($('#DWMain').height() < $(window).height()) {
      $('#DWMain').height($(window).height());
    }
  }
 
  $(window).bind('resize', windowHeight);
 
  windowHeight();
 
  /*
   code for main menu
  */
 
  var roundCorners = function () {
 
    $('#main-menu > ul li div').not('#main-menu ul li ul li').remove();
 
    $('#main-menu > ul li:first').not('#main-menu ul li ul li').prepend($('<div />').css({
        'background-image' : 'url('+DOMAIN+'layout/menu/menu-left-corner.png)',
        'height'           : '30px',
        'width'            : '3px',
        'float'            : 'left'
    })).find('> a').css({
      'padding-left'       : '12px'
    });
 
    $('#main-menu > ul li:last').not('#main-menu ul li ul li').css('float','left').append($('<div />').css({
        'background-image' : 'url('+DOMAIN+'layout/menu/menu-right-corner.png)',
        'height'           : '30px',
        'width'            : '3px',
        'float'            : 'left'
    })).find('> a').css({
      'padding-right'       : '12px'
    });
 
  }
 
  roundCorners();
 
  $('#main-menu ul li a span').each(function () {
    var height = $(this).height();
    if(height  < 26 && height > 0) {
      $(this).parent().css('line-height','24px');
    }
});


 
  $('#main-menu > ul li').not('#main-menu ul li ul li').mouseenter(function () {
 
    $(this).children('ul').css('display','block');
 
    $(this).find('div').remove();
 
    $(this).css({
      'padding'      : '0 0',
      'float'        : 'left'
    }).append($('<div />').css({
      'background-image' : 'url('+DOMAIN+'layout/menu/menu-right-corner-alt.png)',
      'height'           : '36px',
      'width'            : '3px',
      'float'            : 'left'
    })).prepend($('<div />').css({
      'background-image' : 'url('+DOMAIN+'layout/menu/menu-left-corner-alt.png)',
      'height'           : '36px',
      'width'            : '3px',
      'float'            : 'left'
    })).find(' > a').css({
      'background-image' : 'url('+DOMAIN+'layout/menu/menu-bg-alt.png)',
      'padding'          : '7px 12px'
    });
 
  }).mouseleave(function () {
 
    $(this).children('ul').css('display','none');
 
    $(this).css({
      'padding-top'      : '3px'
    }).find(' > a').css({
      'background-image' : 'url('+DOMAIN+'layout/menu/menu-bg.png)',
      'padding'          : '4px 15px'
    });
 
    $(this).find('div').remove();
 
    roundCorners();
 
  });
  
  /*
  Images with Mask
  */
  $('div.item-image img').each(function(i) { MyFlashEmbeb($(this), i); });
  $('#DwTopGraphic img').each(function(i) { MyFlashEmbeb($(this), i); });
  
});
 
function MyFlashEmbeb(selector, i) {
  var ImgSrc = selector.attr("src");
  selector.parent().flashembed({
    src: "Files/System/anm/Layout/Frame.swf",
    wmode: "transparent",
    id: ("flashEmbed" + i)
  },
  {
    'MyImagePath': ImgSrc
  });
}

function clearField( input, defaultValue ) {
  if( ( $('#'+input).val() == "" ) || ( $('#'+input).val().toLowerCase() == defaultValue.toLowerCase() ) )
    $('#'+input).val("");
}
  
/* resets the general search box text to its default value */
function checkIfEmpty( input, defaultValue ) {
  if( ( $('#'+input).val() == "" ) || $('#'+input).val().toLowerCase() == defaultValue.toLowerCase() )
    $('#'+input).val( defaultValue );
}
  
/* checks if the general search box value isn't empty or if its not equal to the default value */
function ValidateSearch( errorMessage, defaultValue ) {
  if( ( $('#searchText').val() == "" ) || ( $('#searchText').val().toLowerCase() == defaultValue.toLowerCase() ) ) {
    alert( errorMessage );
    return false;
  }
}
