var intSlide = 0;
var intSlides;
var intSlideWidth = 1003;
var strBrowser;
var strBrowserVersion;

$(document).ready(function() { 
	$("a.gallery-modal").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false, 'titleShow':false }); 
	show($("#menu-ul li a img:first").attr("src").replace(/[^0-9]/ig, ''));
});

function preloadImages(arrImages) {
	var arrObj = [];	
	for(var i = 0; i < arrImages.length; i++) {
		arrObj[i] = new Image();
		arrObj[i].src = arrImages[i];
	}
}

// PRELOAD
var menuImages = [];
menuImages.push('images/background.jpg');
menuImages.push('images/footer.jpg');
menuImages.push('images/header.jpg');
preloadImages(menuImages);

// ======================================================
// INIT
// ======================================================
function init() {		
	// COUNT SLIDES
	intSlides = $(".content-slide").size();
	intWidth = intSlides * intSlideWidth;			
	// RESIZE SLIDER
	$("#content-slider").css({width: intWidth + "px"});
	if(cId > 0) {
		show(cId);
	} else {
		fader(0);
	}
}

// ======================================================
// SLIDER
// ======================================================
function show(func_id) {
	var func_id;			
	intSlide = func_id;
	$(document).ready(function(){
		fader(1);
		if(func_id == 301) {
			show_gallery(0);
		}
		if(func_id == 302) {
			show_studio(0);
		}
		reset_nav();
		$("#menuimage" + func_id).attr("src","/_cachedir/menu_" + func_id + "_current.gif");
		$('#content-wrapper').scrollTo('#content-slide-' + func_id, 800);
		fader(0);
	});
}

function fader(func_type) {
	if(func_type == 1) {
		$("#main-fader").fadeIn(400);
	} else {
		$("#main-fader").fadeOut(400);
	}
}

// ======================================================
// SLIDER SUBCONTENT - GALLERY
// ======================================================
function show_gallery(func_id, func_gallery) {
	var func_id;
	var func_gallery;
	$(document).ready(function(){
		$('#gallery-wrapper').scrollTo('#gallery-subcontent-'+ func_id,800);
		var gallery_content = $('#gallery-subcontent-images-'+ func_gallery);
		gallery_content.html("<div class=gallery-loading><img src=images/loading_black.gif><br>Bilder werden geladen...</div>");
		gallery_content.load("/includes/ajax_gallery.cfm?eid=" + func_gallery);
	});
}

// ======================================================
// SLIDER SUBCONTENT - STUDIO
// ======================================================
function show_studio(func_id, func_gallery) {

		$('#studio-wrapper').scrollTo('#studio-subcontent-'+ func_id,800);
		var studio_content = $('#studio-subcontent-images-'+ func_gallery);
		studio_content.html("<div class=studio-loading><img src=images/loading_black.gif><br>Bilder werden geladen...</div>");
		studio_content.load("/includes/ajax_studio.cfm?eid=" + func_gallery); 

}	

// ======================================================
// SLIDER SUBCONTENT - Download
// ======================================================
function show_download(func_id, func_gallery, event_link) {

		$('#download-wrapper').scrollTo('#download-subcontent-'+ func_id,800);
		var download_content = $('#download-subcontent-images-'+ func_gallery);
		download_content.html("<div class=download-loading><img src=images/loading_black.gif><br>Bilder werden geladen...</div>");
		download_content.load("/includes/ajax_download.cfm?eid=" + func_gallery + "&event_link=" + event_link); 

}	

// ======================================================
// NAVIGATION
// ======================================================
function reset_nav() {
	for(var i = 0, mId; i < mIds.length; i++) {
		mId = mIds[i];
		$("#menuimage" + mId).attr("src","/_cachedir/menu_" + mId + "_normal.gif");
	}
}

function hover_nav(func_id, func_type) {
	if(intSlide == func_id) {
	
	} else {;
		if(func_type == 1) {
			$("#menuimage" + func_id).attr("src","/_cachedir/menu_" + func_id + "_hover.gif");
		} else {
			$("#menuimage" + func_id).attr("src","/_cachedir/menu_" + func_id + "_normal.gif");	
		}
	}
}

function daumenKino() {
	var $alt = $('#bilderstapel IMG.obersteebene'),
		$neu;
	if($alt.next().length) {
		$neu = $alt.next();
	} else {
		$neu = $('#bilderstapel IMG:first');
	}
	$alt.addClass('mittlereebene');
	$alt.removeClass('obersteebene');
	$neu.css({opacity: 0.0});
	$neu.addClass('obersteebene');
	$neu.animate({opacity: 1.0}, 2000, function() {
		$alt.removeClass('mittlereebene');
	});
}

function initializeGmap() {
	var latlng = new google.maps.LatLng(47.453515,9.037572);
	var settings = {
		zoom: 15,
		center: latlng,
		mapTypeControl: true,
		mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		navigationControl: true,
		navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
		mapTypeId: google.maps.MapTypeId.HYBRID};
		var map = new google.maps.Map(document.getElementById("map_canvas"), settings);
	
	var companyImage = new google.maps.MarkerImage('/images/logo.png',
		new google.maps.Size(100,50),
		new google.maps.Point(0,0),
		new google.maps.Point(50,50)
	);

	var companyShadow = new google.maps.MarkerImage('/images/logo.png',
		new google.maps.Size(130,50),
		new google.maps.Point(0,0),	
		new google.maps.Point(65, 50));

	var companyPos = latlng;

	var companyMarker = new google.maps.Marker({
		position: companyPos,
		map: map,
		icon: companyImage,
		//shadow: companyShadow,
		title:"Gehrig Liegenschaften",
		zIndex: 3});
	
}

$(document).ready(function() {
	if($('#bilderstapel').length) setInterval(daumenKino, 6000);
	if($('#map_canvas').length) initializeGmap();
	if($("#kontakt-danke").length) {
		$('#kontakt-danke').show();
		$('<a href="#kontakt-danke"> </a>').fancybox({
			'hideOnContentClick': false,
			'frameWidth': 400,  
			'frameHeight':100,
			'overlayOpacity': 0.5,
			'onClosed': function() {
				$('#kontakt-danke').hide();
			}
		}).trigger('click');

	}
	init();
});
