// JS Document - Jasmin Memisevic UI/Web designer - frontend developer // jasmin.memisevic@gmail.com // jasmin.memisevic @ skype // //

// google maps
function initialize() 
{
	var lokacija = new google.maps.LatLng(44.08068, 15.18900);
	var opcije = {
		zoom:16,
		center:lokacija,
		mapTypeControl:false,
		mapTypeId:google.maps.MapTypeId.HYBRID
	}
	
	var map = new google.maps.Map(document.getElementById("googleMap"), opcije);
	
	marker = new google.maps.Marker({
		map:map,
		draggable:false,
		animation:google.maps.Animation.DROP,
		position:lokacija
	});

}
	
function loadMap() 
{
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
	document.body.appendChild(script);
}

// menu class
(function($){
 	$.fn.extend({ 
 		langMenu: function(){
    		return this.each(function(){
				var dugme = $(this).find('#langBtn');
				var menu = $(this).find('#langMenu');
				var menuDugme = $(this).find('#langMenu a');
				var intHeight = menu.css('height');
				var intOpacity = menu.css('opacity');
				var timeOutVrijeme = 5;
				
				menu.css('height', 0);
				menu.css('opacity', 0);
				
				function timer(){
					tajmer = window.setInterval(
						function(){
							if(timeOutVrijeme > 0){
								timeOutVrijeme =- 1;
							}
							else{
								window.clearInterval(tajmer);
								menu.animate({
									opacity:0,
									height:0
								}, 300)
							}
						}, 1000 )};
				
				dugme.click(function(event){
					event.preventDefault();
					timeOutVrijeme = 5;
					menu.animate({
						opacity:intOpacity,
						height:intHeight
				    }, 300, function(){
						timer();
				    });
				})
				
				menu.mouseover(function(){
					timeOutVrijeme = 5;
				})
				
				menuDugme.click(function(){
					window.clearInterval(tajmer);
					timeOutVrijeme = 5;
					menu.animate({
						opacity:0,
						height:0
				    }, 300);
				})
														
    		});
    	}
	});
})(jQuery);

// form field highlighter
(function($){
 	$.fn.extend({ 
 		inputGlow: function(){
    		return this.each(function(){
				var field = $(this);
				field.focus(function(){
					field.addClass('activeInput');
				});
				
				field.blur(function(){
					field.removeClass('activeInput');
				});
			
    		});
    	}
	});
})(jQuery);

$(document).ready(
	function(){

		/// int langMenu
		$('#langMenuWrap').langMenu();
		
		/// hr fix and css
		$('div.or').prepend("<hr />").append("<hr />");
		$('#cta div.or hr:first-child, .col.three div.or hr:first-child').css('float', 'left');
		$('#cta div.or hr:last-child, .col.three div.or hr:last-child').css('float', 'right');
		$('#scrollerWrap .group a:nth-child(2n+2)').css('margin', '0px');
		$('#cta div.or hr:last-child, .col.two img.picture:last-child, .col.three div.or hr:last-child').css('marginRight', '20px');
		$('#cta div.or hr:first-child, #cta div.or hr:last-child, .col.three div.or hr:first-child, .col.three div.or hr:last-child').css('marginTop', '9px');
		$('#ContactForm p:nth-child(1), #ContactForm p:nth-child(3)').css('marginRight', '17px');
		$('.col.two img.picture:last-child').css('marginLeft', '20px');
		$('#cta div.or hr:first-child, .col.two img.picture:last-child, .col.three div.or hr:first-child').css('marginBottom', '20px');

		// input field highlight
		$('#ContactForm p input, #ContactForm p textarea').inputGlow();
				
		/// int scroller
		$('#browsable').scrollable({vertical: true, mousewheel: true});
		
		/// go go flash
		$('#flashSlideShow').flashembed(
			{
				src:		'static/swf/slideshow.swf', 
				wmode:		'transparent'
			},
			{
				putDoXml:	'xml/slike.xml'
			}
		);
		
		/// int fancybox
		$('div.group a, div.images a').fancybox({
			'speedIn':			400, 
			'speedOut':			400, 
			'overlayShow':		true,
			'overlayOpacity':	0.6,
			'overlayColor':		'#fff'
		});

		/// call google maps
		$('#googleMap a').click(
			function(event){
				event.preventDefault();
				loadMap();
			}
		);
		
			$.simpleWeather({
				location: 'zadar, croatia',
				unit: 'c',
				success: function(weather) {
					$("#weather #tempHiLow").append(weather.high+"&deg; "+weather.units.temp+" / "+weather.low+"&deg; "+weather.units.temp);
					$("#weather #hum").append(weather.humidity+"%");
					$("#weather #pres").append(weather.pressure+" mb");
					$("#weather #viz").append(weather.visibility+" km");
					$("#weather #wind").append(weather.wind.direction+" "+weather.wind.speed+" "+weather.units.speed);
					$("#weather #tempNow").append(weather.currently+", "+weather.temp+"&deg; "+weather.units.temp);
					$("#weather").css('background-image', 'url('+weather.image+')');
					$("#weather").css('background-repeat', 'no-repeat');
					$("#weather").css('background-position', '-60px -20px');
				},
				error: function(error) {
					$("#weather").html(" ");
					$("#weather").css('width', '0');
				}
			});
		
	}
);	
