$(function () {
  
  var msie6 = $.browser == 'msie' && $.browser.version < 7;
  
  if (!msie6) {
    var top = $('#navigation').offset().top - parseFloat($('#navigation').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();
      
      // whether that's below the form
      if (y >= top) {
        // if so, ad the fixed class
        $('#navigation').addClass('fixed');
      } else {
        // otherwise remove it
        $('#navigation').removeClass('fixed');
      }
    });
  }  
});

var timeOut;
var timeOutClose;
var delayTime = 350;

function delayedCall(t) {
	//timeOut = setTimeout(function() { 
	showSubMenu(t); //}, delayTime);
}

function removeDelayedCalls() {
	try {
		clearTimeout(timeOut);
	}
	catch(ex) { }
}

function removeDelayedCloseCalls() {
	try {
		clearTimeout(timeOutClose);
	}
	catch(ex) { }
}

function delayedCloseCall(t) {
	//timeOutClose = setTimeout(function() { 
	hideSubMenu(t); 
	//}, delayTime + 250);
}

function hideMenu() {
	$('.submenublock').css("display", "none");
	removeDelayedCalls();
	removeDelayedCloseCalls();
}

function showSubMenu( subMenu ){
/*	hideMenu();
	$("#" + subMenu).css("display", "block");*/
    var subMenuItem = 'drop' + subMenu;
	//alert(document.getElementById(subMenuItem).className);
	document.getElementById(subMenuItem).className = 'show';
    var subMenuItem = 'nav' + subMenu;
	document.getElementById(subMenuItem).className = 'hover';
    var subMenuItem2 = 'navItem' + subMenu;
	//document.getElementById(subMenuItem2).className = 'selectedHide';
	$('#'+subMenuItem2).attr("class", "selectedHide");
	//var dropMe = '#drop' + subMenu ;
	//$(dropMe).slideDown('slow' , function(){									 
	//	document.getElementById(subMenuItem).className = 'show';
	//});	
}
function hideSubMenu( subMenu ){
	//$("#" + subMenu).css("display", "none");
    var subMenuItem = 'drop' + subMenu;
	//alert(document.getElementById(subMenuItem).className);
	document.getElementById(subMenuItem).className = 'hidden';
    var subMenuItem = 'nav' + subMenu;
	document.getElementById(subMenuItem).className = 'hoverHide';
    var subMenuItem2 = 'navItem' + subMenu;
	//document.getElementById(subMenuItem2).className = 'selected';
	$('#'+subMenuItem2).attr("class", "selected");
	
	//var dropMe = '#drop' + subMenu ;
	//$(dropMe).slideUp('slow' , function(){									 
	//	document.getElementById(subMenuItem).className = 'hidden';
	//});
}

function openLink(url){
	location.href= url ;
}

var swap_text_boxes = [];

function init_swap_text_boxes(){
  //Store the default value for each box
  $('input[type=text][value].swaptextbox').each(function() {
    swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
  });
  //Add focus and blur events to set or clear the value
  $('input[type=text][value].swaptextbox').bind('focus', function() {
    if($(this).val() == swap_text_boxes[$(this).attr('id')]) {
      $(this).val('');
    }
  });
  $('input[type=text][value].swaptextbox').bind('blur', function() {
    if($(this).val() == '') {
      $(this).val(swap_text_boxes[$(this).attr('id')]);
    }
  });
  
  $('input[type=password][value].swaptextbox').each(function() {
    swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
  });
  //Add focus and blur events to set or clear the value
  $('input[type=password][value].swaptextbox').bind('focus', function() {
    if($(this).val() == swap_text_boxes[$(this).attr('id')]) {
      $(this).val('');
    }
  });
  $('input[type=password][value].swaptextbox').bind('blur', function() {
    if($(this).val() == '') {
      $(this).val(swap_text_boxes[$(this).attr('id')]);
    }
  });
}

$(document).ready(function(){ init_swap_text_boxes(); });