$(document).ready(function(){
	
	$('.login a').click(function(){
		$(this).next('.box').toggle();
		$(this).toggleClass('active');
	});
    
	
	$('.lang a.main').click(function(){
		
		$(this).toggleClass('active');
											
		var dl = $(this).next('ul');

		if(dl.is(':visible')){
			dl.hide();
		} else {
			dl.show();
		}
		
	});
    
	
	$('.lang ul li a').click(function(){
		$('.lang a.main').html($(this).html());
		$('.lang a.main').attr('title', $(this).attr('title'));
		$('.lang a.main').removeClass('active');
		$(this).parent().parent().hide();
	});
    

	$('.team_list .tp, .partners_list .tp').mouseover(function(){
		$(this).parent().addClass('hovered');
	}).mouseout(function(){
		$(this).parent().removeClass('hovered');	
	});
    
	
	$('.facilities_list dd, .active_overview li').eq(0).addClass('bt');
	$('.facilities_list dd, .active_overview li').eq(1).addClass('bt');
	
	$('.contact_form .drop ins').click(function(){
		$(this).next().toggleClass('visible');
	});
    
	
	$('.contact_form .drop li a').click(function(){
		$('.contact_form .drop ins').html($(this).attr('rel'));
		$('.contact_form .drop input').val($(this).attr('rel'));
		$('.contact_form .drop .drop_holder').removeClass('visible');
		return false;
	});
    
    
    
    $('.dropdowns .dropdown').click(function(){
        
        $('.dropdowns .drop_holder').removeClass('visible');
        $(this).find('.drop_holder').addClass('visible');
        $('#state, #country').jScrollPaneRemove();
    
    });
    
    $('.dropdowns .dropdown').click(function(){
        
        $('#state, #country').jScrollPane();
        
        $('.dropdowns .drop_holder').removeClass('visible');
        $(this).children('.drop_holder').addClass('visible');
    
    });    
    
    $('.dropdowns .dropdown ol li a').click(function(){
    
        $(this).parent().parent().parent().parent().parent().prev().html($(this).html());
        $(this).parent().parent().parent().parent().parent().removeClass('visible');
        $('#state, #country').jScrollPaneRemove();
        
        return false;
    }); 
    
    $('.dropdowns .dropdown, .contact_form .drop').click(function(e){
        e.stopPropagation();
    });
    
    $(document).click(function(){
        $('.dropdowns .drop_holder, .contact_form .drop_holder').removeClass('visible');
    });

         
	$('input[type=text], input[type=password], 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;
	        }
	    });		    
	});
    
	
	$('.btm_line .right a').click(function(){
		$('.terms, #overlay').show();
		$(document).scrollTo( '0', 600);
	});
	
	$('.close').click(function(){
		$('.terms').hide();
		$('#overlay').hide();
	});
    
	$('.btm_line .right2 a').click(function(){
		$('.privacy, #overlay').show();
		$(document).scrollTo( '0', 600);
	});
	
	$('.close').click(function(){
		$('.privacy').hide();
		$('#overlay').hide();
	});

    if ($.browser.msie && $.browser.version == 6){
		$('#spots .spot_3 ul li:first-child, .partners_holder div a:first-child, .mhl .navi a:first-child').addClass('first-child');
		
		$('.partners_list li .tp').mouseover(function(){
			$(this).children().css('top', '-200px');
		}).mouseout(function(){
			$(this).children().css('top', '0px');
		});
		
		$('#overlay').height($(document).height() + 'px');
	}
});

var timer = null;

function ScrollStart(dir){
	stopScroller();
	timer = window.setInterval( function() { scrollIt( dir ) }, 10);
	document.onmouseup=stopScroller;
}

function scrollIt(dir){
	var obj = document.getElementById('partners_holder');

	switch(dir){
		case 'left': obj.scrollLeft-=3; break;
		default: obj.scrollLeft+=3; break;
	}
}

function stopScroller(){
	window.clearInterval( timer );
}

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);
