$(document).ready(function() {
   var overlayColor = $('#fancy_overlay').css('background-color') || '#2c2c2c'; 
   $("a.login").fancybox({
      'padding':12,
	  'overlayOpacity':0.2,
	  'overlayColor':overlayColor,
	  'showCloseButton':false,
	  'frameWidth':400,
	  'frameHeight':208,
	  'hideOnContentClick':false,
	  'callbackOnShow':modalStart});
   
    $("a.img").hover(function() {
      if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) <= 8) {
         $(this).stop(false, true).toggleClass('imgHover');
	  } else {
         $(this).stop(false, true).toggleClass('imgHover', 200);
      }
	});
	$(window).scroll(function() {
      ribbonPosition()
	});
	ribbonPosition();
	$.localScroll(); searchInputEffect(); buttonStyles();
	if(!jQuery.browser.msie) {
 	     $("a.img, div.img, .textInput, input[type='text'], input[type='password'], textarea").addClass('rounded'); roundCorners();
	}
});


function modalStart() {
   $('#fancy_inner').addClass('rounded');
   roundCorners()
}
function ribbonPosition() {
   var t = $(window).scrollTop();
   var h = $(window).height();
   var offset = $(window).height() / 25;
   var zoneSize = $(window).height() / 3;
   var zoneOne = t + zoneSize + offset;
   var zoneTwo = t + zoneSize * 2 - offset;
   $(".ribbon .wrapAround").each(function() {
      var obj = $(this); var objH = obj.height(); var offset = obj.offset(); if(offset.top + objH <= zoneOne) {
         $(this).css('background-position', '0 0')}
      else if(offset.top >= zoneTwo) {
         $(this).css('background-position', '0 -104px')}
      else {
         $(this).css('background-position', '0 -52px')}
      }
   )}
function searchInputEffect() {
   var searchFocus = false, searchHover = false, searchCtnr = $('#Search');
   searchInput = $('#SearchInput'), searchSubmit = $('#SearchSubmit');
   searchCtnr.hover(function() {
      if(!searchFocus)$(this).addClass('searchHover'); searchHover = true}
   , function() {
      if(!searchFocus)$(this).removeClass('searchHover'); searchHover = false}
   ).mousedown(function() {
      if(!searchFocus)$(this).removeClass('searchHover').addClass('searchActive')}
   ).mouseup(function() {
      searchInput.focus(); searchSubmit.show(); searchFocus = true}
   );
   searchInput.blur(function() {
      if(!searchHover) {
         searchCtnr.removeClass('searchActive'); searchSubmit.hide(); searchFocus = false}
      }
   )}
function buttonStyles() {
   $("button:not(:has(span),.noStyle), input[type='submit']:not(.noStyle), input[type='button']:not(.noStyle)").each(function() {
      var b = $(this), tt = b.html() || b.val(); if(!b.html()) {
         b = ($(this).attr('type') == 'submit') ? $('<button type="submit">') : $('<button>'); b.insertAfter(this).addClass(this.className).attr('id', this.id); $(this).remove(); }
      b.text('').addClass('btn').append($('<span>').html(tt)); }
   );
   var styledButtons = $('.btn');
   if(jQuery.browser.mozilla || jQuery.browser.webkit) {
      styledButtons.children("span").css("margin-top", "-1px")}
   styledButtons.hover(function() {
      $(this).addClass('submitBtnHover')}
   , function() {
      $(this).removeClass('submitBtnHover')}
   )}
function roundCorners() {
   $('.rounded, .ui-corner-all').css( {
      '-moz-border-radius':'4px', '-webkit-border-radius':'4px', 'border-radius':'4px'}
   )}
