/**
* DOM ready
*/
$(document).ready( function(){	
	
	//form - text input - change styles
	$('input, textarea').addClass("idleField");
	$('input, textarea').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('input, textarea').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});	
	
	
	//a link - hover
	$('a').mouseover(function() {
		$(this).addClass("over");
	});	
	$('a').mouseout(function() {
		$(this).removeClass("over");
	});	
		
	
	//form
	$('input, textarea')
		.focus(function(){
			$(this).parent().css('background-color', '#fff');
		})
		.blur(function(){
			$(this).parent().css('background-color', '#f5f5f5');
		});
		
	//first letter
	$orig = $('.transform_first_letter');
	$text = $.trim($orig.html());	
	if($text != ''){
		$letter = $text.slice(0, 1);
		$span = '<span class="first_letter">' + $letter.toUpperCase() + '</span><br><br>';		
		$orig.html('').append($span + $text.slice(1));
	}
});	

/**
* Window loaded
*/
$(window).load(function() {
	//image slider
	if($('.content_img img').length > 0){
		$height = 0;
		
		$('.content_img img').each(function(){
			if($(this).height() > $height)
				$height = $(this).height();
		});
		$('.content_img').height($height);		
	}
	
	$i = -1;
	$timer = 2000;
	$total = $('.content_img img').length;
	$nextIMG = function(){
		$('.content_img img').eq($i++).fadeOut();
		
		if($i >= $total)
			$i = 0;
		
		$('.content_img img').eq($i).fadeIn();
		
		if($total > 1)
			$iInterval = setTimeout($nextIMG, $timer);
	}
	$nextIMG();
	
	
	//google maps
	try{
		if($arrGoogleMaps !== undefined){
			for(var i in $arrGoogleMaps) {
				$objGoogleMap = $arrGoogleMaps[i];
				$map = $google_maps($objGoogleMap);
				
				if($map)
					$google_maps_marker($map, $objGoogleMap);
			}
		}
	} catch(e){}
	
});


/**
* Array - shuffle elements
*/
$array_shuffle = function(o){ 
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};




/**
* Google Maps
*/
$google_maps = function($obj){ 
	if($obj.div === undefined)
		return false;	
		
	$div = $.trim($obj.div);
	if($('#' + $div).length == 0)
		return false;	
		
	$div = $('#' + $div).get(0);
				
	var myOptions = {		
		mapTypeControl: false,
		mapTypeControlOptions: {  
			position: google.maps.ControlPosition.TOP_LEFT,
			style: google.maps.MapTypeControlStyle.DROPDOWN_MENU  
		},
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		navigationControl: true,
		navigationControlOptions: {  
			position: google.maps.ControlPosition.TOP_RIGHT,
			style: google.maps.NavigationControlStyle.SMALL  
		},
		noClear: true,
		scaleControl: false,
		zoom: 10
	};	
	var map = new google.maps.Map($div, myOptions);	
	return map;	
};

$google_maps_marker = function($map, $obj){ 
	if($obj.markers === undefined)
		return false;

	var geocoder = new google.maps.Geocoder();
	if (geocoder) {
	
		for (var i in $obj.markers) {
			$objGoogleMarker = $obj.markers[i];
			if ($objGoogleMarker.address === undefined) 
				continue;
			
			$address = $.trim($objGoogleMarker.address);
			if ($address == '') 
				continue;
			
			$image = null;
			if ($objGoogleMarker.image !== undefined) {				
				$imageSize = null;
				if ($objGoogleMarker.imageW !== undefined && $objGoogleMarker.imageH !== undefined)
					$imageSize = new google.maps.Size(
						$objGoogleMarker.imageW, 
						$objGoogleMarker.imageH
					);
				
				$image = new google.maps.MarkerImage(
					$objGoogleMarker.image, null, null, null, $imageSize
				);
			}
			
			geocoder.geocode({'address': $address}, 
				function(results, status) {
					if (status == google.maps.GeocoderStatus.OK){
						$map.setCenter(results[0].geometry.location);					
						
						var marker = new google.maps.Marker({
							clickable: false,
							icon: $image,
							map: $map, 
							position: results[0].geometry.location
						});
					} else{
						alert("Geocode error: " + status);
					}
				}
			);
		}
	}
	

};






























