/**
 * JS by Mateusz Czpak
 **/

$(document).ready( function(){
	if($('#salon').length >0){
		init_salon();
		dom_tak();
	}
	
	if($('.button_intro').length >0){
		init_intro();
	}
	else if($('#salon').length == 0){ //scrollowanie pod tekstu
		var to_scroll = $(document).height()+35;
		$(window).scrollTop(to_scroll);
		$(document).scrollTop(to_scroll);
	}
	
	if($('.bmw').length >0){
		Cufon.replace('.bmw',{hover: true,fontFamily: 'bmw'});
	}
	
	//kontakt
	if($('#mapa_google').length > 0){
		if($('#mapa_google').hasClass('wroclaw')){
			googlemap('mapa_google', 51.076358, 17.008595);
		}
		else{
			googlemap('mapa_google', 52.2363088, 20.9565245);
		}
	}
	
});

function dom_tak(){
	if(document.location.hash=='#dom_tak'){
		$('#iframe_form').attr('src', 'form_serwis/index.html#tak');
		document.location.hash = '';
	}	
};

function googlemap(id_cont, wsp_x, wsp_y){

	var myOptions = {
		zoom: 15,
		center: new google.maps.LatLng(wsp_x, wsp_y),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}

	var map = new google.maps.Map(document.getElementById(id_cont), myOptions);
	if($('#mapa_google').hasClass('wroclaw')){
		var icon = new google.maps.MarkerImage("images/marker.png", new google.maps.Size(118, 91), new google.maps.Point(0, 0), new google.maps.Point(130, 89));
	}
	else{
		var icon = new google.maps.MarkerImage("images/marker.png", new google.maps.Size(118, 91), new google.maps.Point(0, 0), new google.maps.Point(86, 89));
	}
	var marker = new google.maps.Marker({position:new google.maps.LatLng(wsp_x, wsp_y), icon: icon, map:map});
}

function init_salon(){
	if(document.location.hash=='#wroclaw'){
		//alert('wroclaw');
		//document.location.hash = '';
		$('#content').addClass('wroclaw');
	}	
	else{
		//alert('wroc');
		//document.location.hash = '';
		$('#content').addClass('warszawa');
	}
	
}

function init_intro(){
	$('.button_intro').each( function(){
		var hover_to_show = $(this).children();
		$(this).mouseenter( function(){
			hover_to_show.stop().fadeTo(200, 1, 'linear');
		});	
		
		$(this).mouseleave( function(){
			hover_to_show.stop().fadeTo(200, 0, 'linear');
		});
	});
}

//funckcja obsŁugująca lightbox
/*
function init_lightbox(box_to_show){

	$('.close_box').click(function(){
		$('#lightbox_cont').fadeOut(200, function(){
			$('#lightbox_background').fadeOut(200);
		});
	});
		
	$('#lightbox_background').fadeIn(300, function(){
		$(this).css({'filter':'alpha(opacity=50)', '-ms-filter': 'progid:DXImageTransform.Microsoft.Alpha(Opacity=50)'});
		$('#lightbox_cont').fadeIn(200);
	});
}
*/
