
/* === jQuery Functions === */

$(document).ready(function(){
	
	initCufon();
	initLogos();
	clearValues();
	toggleRightMenu();
	ie6Fixes();
	
	
	function initCufon(){
		
		Cufon.replace('.main-menu li a', {
			fontFamily: 'Helen Bg',
			fontSize: '16px',
			hover: true
		});
		
		Cufon.replace('.heading h2', {
			fontFamily: 'Helen Bg',
			fontSize: '19px'
		});
			
	}
	
	function initLogos(){
		
		$('#logos li a .color').css('opacity', 0);
		
		$('#logos li a').mouseover(function(){
			$(this).children('.gray').stop().animate({ opacity : 0 }, 500);
			$(this).children('.color').stop().animate({ opacity : 1 }, 500);
		}).mouseout(function(){
			$(this).children('.gray').stop().animate({ opacity : 1 }, 500);
			$(this).children('.color').stop().animate({ opacity : 0 }, 500);
		});
		
	}

	function clearValues(){	
		$('input[type=text], textarea').each(function(){			
		    var d_value = this.value;			    
		    $(this).focus(function(){
		        if(this.value == d_value){
		            this.value = '';
		        }
		    });			    
		    $(this).blur(function(){
		    	if(this.value == ''){
		            this.value = d_value;
		        }
		    });		    
		});
	}

	function toggleRightMenu(){
		
//		$('.menu-right li a.main').click(function(){
//			
//			if (!$(this).hasClass('trigger')) {
//				$(this).animate({ 
//					marginTop: "-44px"
//				}, 250 );
//				$(this).addClass('trigger');
//				$(this).parent().children('ul').slideToggle(250);
//				
//			} else {
//				$(this).animate({ 
//					marginTop: "0px"
//				}, 100 );
//				$(this).removeClass('trigger');
//				$(this).parent().children('ul').slideToggle(100);
//			}
//			return false;
//		});			
//		
		$('.menu-right li a.main').mouseenter(function(){
			if (!$(this).hasClass('trigger')) {
				$(this).addClass('trigger');
				height = (280 - $(this).parent().children('ul').height());
				margin = ((height < 0) ? "-" + (44 - height) + "px" : "-44px");
				$(this).animate({ 
					marginTop: margin
				}, 250);
				$(this).parent().children('ul').slideToggle(250);
			} 
		});			
		
		$('.menu-right > li').mouseleave(function(){
			if ($('a.main', $(this)).hasClass('trigger')) {
				$('a.main', $(this)).animate({ 
						marginTop: "0px"
					}, 100 );
				$('a.main', $(this)).removeClass('trigger');
				$('a.main', $(this)).parent().children('ul').slideToggle(100);
			}
		});
		
	}
	
	function ie6Fixes(){
		
		if ($.browser.msie && $.browser.version == 6){
			$("#homePhoto .menu-left li:first-child, #homePhoto .menu-right li li:first-child").addClass("first-child");
		}
		
	}
    
    $('#logos li a').click(function(e){
        window.location.href = $(this).attr('href');
        e.preventDefault();
    });
	
	
	
});


/* === Remove outline in IE === */

function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, true); 
		return true; 
	}else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}else{ 
		return false; 
	} 
}

function hideFocusBorders(){
var theahrefs = document.getElementsByTagName("a");
	if (!theahrefs){return;}
		for(var x=0;x!=theahrefs.length;x++){
		theahrefs[x].onfocus = function stopLinkFocus(){this.hideFocus=true;};
	}
}

addEvent(window, 'load', hideFocusBorders);
