$(function() {	
	
	jQuery.httpbase = function( ){
		return $('base')[0].href;
	}
	
	jQuery.loadcm = function( uri, htmlElementId ){
		$.ajax({ url: uri, success: function( data ){
	        $('#' + htmlElementId).html( data );
	    }});
	}	
	
	$(".clickable").click( function() {					
		document.location.href=$('a:eq(0)',this).attr('href');
		return false;
	});

	//SUPPORT
	var values = new Array();
	var inputs = $(":input");
	
	inputs.each(function(i,e) {
		values[i] = e.value;
		if($(e).hasClass("clear")) {
			$(e).focus(function() {			
				if(e.value == values[i]) {				
					e.value = '';
				}
			});
			$(e).blur(function() {
				if(e.value == '') {
					e.value = values[i];
				}
			});
		} else if($(e).is(".password.text")) {
			$(e).focus(function() {		
				$(this).addClass('hide');
				$(this).parent("form").find(".password.input").removeClass('hide');
				$(".password.input",$(this).parent("form")).focus();					
			});			
		} else if($(e).is(".password.input")) {
			$(e).blur(function() {
				if(e.value == '') {
					$(this).addClass('hide');
					$(this).parent("form").find(".password.text").removeClass('hide');
				}
			});
		}
	});
	
	$("#nav .items a.sub").each(function(i,e){
		$(this).mouseover(function(d){
			var ml = i*117-i;
			$('#subnav').hide();
			$('#subnav .nav').hide();
			$('#subnav .nav').eq(i).show();
			$('#subnav').css('marginLeft',ml+'px');
			$('#subnav').show();
			$.setHeight();
			$(document).mouseover(function(d){
				if (!$(d.target).parents().andSelf().is('#subnav')) {
					$('#subnav').hide();
					$('#subnav .nav').hide();
					$(document).unbind('click');
				}							
			});
			d.stopPropagation();
		});		
	});	
	
	$("#sfeer .slide img").hide();
	$("#sfeer .slide img:eq(0)").show();
	$("#sfeer .slide img:eq(0)").addClass("is_active");
	
	$("#sfeer .slide").each(function(){
		setInterval( "$.slideShow('#sfeer .slide img')", 7500 );
	});
	$.setHeight();	
});

$.setHeight = function() {		
	$(".transparency").each(function() {		
		$(this).css("height",$(this).parent().height());
		$(this).css("width",$(this).parent().width());
	});	
}

$.slideShow = function(slides) {
	$(slides).each( function(i,elem) {
		if($(elem).hasClass('is_active')) {				
			active = i;
			next =  $(slides).eq(active).next().length ? i+1 : 0;
		}			
	});	
	$(slides).eq(active).fadeOut('slow');
	$(slides).eq(active).removeClass('is_active');
	$(slides).eq(next).fadeIn('slow');
	$(slides).eq(next).addClass('is_active');
}

 

