$(document).ready(function(){
	
	modalWindows();
	initMainMenu();
	initModalWindows();
	initLastChilds();
	initAccordeon();
	clearValues();
	ie6Fixes();
	
	
	function modalWindows(){
			
			$('#reg_user').css('margin-top', '-200px');
                        $('#reg_user').css('margin-left', '-200px');

                        $('#forgot_pass').css('margin-left', '-200px');
                        $('#forgot_pass').css('margin-top', '-200px');

						$('#change_pass').css('margin-top', '-200px');
                        $('#change_pass').css('margin-left', '-200px');
                        
                        $('.forgot_pass').click(function(){
				$('#overlay, #forgot_pass').show();
				return false;
			});

                        $('.reg_user').click(function(){
				$('#overlay, #reg_user').show();
				return false;
			});
			
                        $('.change_pass').click(function(){
				$('#overlay, #change_pass').show();
				return false;
			});			

                       $('#overlay').click(function(){
				$('#overlay, #reg_user, #forgot_pass, #change_pass').hide();
				return false;	
                       });

		}	
	
	function initMainMenu(){
		
		$('#main_menu ul li').mouseover(function(){
			$(this).children('a').addClass('hovered');
			$(this).find('ul.level2').show();
				
		});
		
		$('#main_menu ul li').mouseleave(function(){
			$(this).children('a').removeClass('hovered')
			$(this).find('ul.level2').hide();
		});
		
		$('#main_menu ul.level2 li').mouseover(function(){
			$(this).children('a').addClass('hovered');
			$(this).find('ul.level3').show();
				
		});
		
		$('#main_menu ul.level2 li').mouseleave(function(){
			$(this).children('a').removeClass('hovered')
			$(this).find('ul.level3').hide();
		});
		
	}
	
	function initModalWindows(){
		$('a[rel]').overlay({
			mask:{
				color: '#000',
				loadSpeed: 0,
				opacity: 0.5
			},
			onBeforeLoad: function(){
				var wrap = this.getOverlay().find('.contentWrap');
				wrap.load(this.getTrigger().attr('href'));
			},
			closeOnClick: false
		});
	}
	
	
	function initLastChilds(){
		$('#main_menu ul li:last-child a').css('background-image', 'none');
		$('#main_menu ul li ul li ul li:last-child').css('background-image', 'none');
	}
	
	function initAccordeon(){			
		$('.box .left a').click(function(){
			$(this).toggleClass('open');
			$(this).parent().parent().parent().children('.box-inner').slideToggle('normal');
			return false;	
		});
	}
	
	function clearValues(){
		//$('input[type=text], input[type=password], textarea').each(function(){
                $('#keyword').each(function(){
		    var field_value = this.value;
		    
		    $(this).focus(function(){
		        if(this.value == field_value){
		            this.value = '';
		        }
		    });
		    
		    $(this).blur(function(){
		    	if(this.value == ''){
		            this.value = field_value;
		        }
		    });
		});
	}
	
	function ie6Fixes(){
		
		if ($.browser.msie && $.browser.version == 6){
			$('.accent_tabs li:first-child, .right_side .col .inner ul li:first-child, .section_left .left ul li:first-child').addClass('first-child');
		}
		
	}
	
	
});

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);
