var iCurrentThemeItem = 1;
var iThemeCount = 0;

$(document).ready(function(){
	iThemeCount = $('.theme-item').length;
	
	if (iThemeCount > 1) {
		$('#mask-slider').css('width', (iThemeCount * 980) + 'px');
			
		$('#theme .inside').append('<div id="move-left" onclick="theme_move_left()">&nbsp;</div>');
		$('#theme .inside').append('<div id="move-right" onclick="theme_move_right()" style="display:none">&nbsp;</div>');
		
		if ($('.theme-detail').length > 1) {
			$('#navi-sub').prepend('<ul></ul>');
		}
		
		for (var i = 1; i <= iThemeCount; i++) {
			
			if ($('#mask-slider .theme-item').length < iThemeCount) {
				$('#theme-item-' + i).appendTo('#mask-slider');
			}
			
			$('#theme-item-' + i).css('position', 'absolute');
			$('#theme-item-' + i).css('top', '0');
			$('#theme-item-' + i).css('left', (980 * (i - 1)) + 'px');
			
			$('#theme-item-' + i).clone().appendTo('#slider');
			
			$('#slider #theme-item-' + i).css('opacity', '0.4');
			$('#mask-slider #theme-item-' + i).css('opacity', '1');
			
			if ($('.theme-detail').length > 1) {
				var sName = $('#theme-detail-' + i + ' h2').html();
				$('#navi-sub ul').append('<li><a href="javascript:theme_move_to(' + i + ')">' + sName + '</a></li>');
			}
		}
	
		$('#navi-sub li:first').addClass('active');
		$('.theme-detail:not(:first)').hide();
	}
	
	$('.gallery .images a').append('<img class="pic-hover" src="/assets/images/pic_over.png" width="79" height="79" />');
	$('.gallery .images a .pic-hover').fadeOut(0);
	$('.gallery .images a').hover(function(){
		$(this).children('.pic-hover').fadeIn('fast');	
	}, function(){
		$(this).children('.pic-hover').fadeOut('fast');	
	});
	
	$('.videos .images a').append('<img class="pic-hover" src="/assets/images/pic_over_video.png" width="212" height="168" />');
	$('.videos .images a .pic-hover').fadeOut(0);
	$('.videos .images a').hover(function(){
		$(this).children('.pic-hover').fadeIn('fast');	
	}, function(){
		$(this).children('.pic-hover').fadeOut('fast');	
	})
	
    $(".fancybox").fancybox({
    	padding: 3,
    	loop: false,
    	prevEffect: 'fade',
    	nextEffect: 'fade'
    });
	
    $("a.video").fancybox({
    	maxWidth: 800,
		maxHeight: 600,
		fitToView: false,
		width: '70%',
		height: '70%',
		autoSize: false,
    	padding: 3,
    	loop: false,
    	prevEffect: 'fade',
    	nextEffect: 'fade'
    });
});

function theme_move_left() {
	if (iCurrentThemeItem >= iThemeCount) return true;
	
	$('#slider').animate({left: '-=980'}, 'slow');
	$('#mask-slider').animate({left: '-=980'}, 'slow');
	
	iCurrentThemeItem++;
	
	theme_show_item(iCurrentThemeItem);
}

function theme_move_right() {
	if (iCurrentThemeItem <= 1) return true;
	
	$('#slider').animate({left: '+=980'}, 'slow');
	$('#mask-slider').animate({left: '+=980'}, 'slow');
	
	iCurrentThemeItem--;
	
	theme_show_item(iCurrentThemeItem);
}

function theme_move_to(iIndex) {
	if (iCurrentThemeItem == iIndex) return true;
	
	$('#slider').animate({left: ((iIndex - 1) * -980) + 'px'}, 'slow');
	$('#mask-slider').animate({left: ((iIndex - 1) * -980) + 'px'}, 'slow');
	
	iCurrentThemeItem = iIndex;
	
	theme_show_item(iCurrentThemeItem);
}

function theme_show_item(iIndex) {
	if (iCurrentThemeItem == iThemeCount) $('#move-left').hide();
	else $('#move-left').show();
	if (iCurrentThemeItem == 1) $('#move-right').hide();
	else $('#move-right').show();
	
	$('#navi-sub li:eq(' + (iIndex - 1) + ')').addClass('active');
	$('#navi-sub li:not(:eq(' + (iIndex - 1) + '))').removeClass('active');
	
	$('.theme-detail:not(:eq(' + (iIndex - 1) + '))').hide();
	$('.theme-detail:eq(' + (iIndex - 1) + ')').show();
}

function initialize() {
    var map;
    var mapCenter = new google.maps.LatLng(51.220446, 7.629597);
    var mapMarker = new google.maps.LatLng(51.220446, 7.629597);

    var mapStyle = [{
        stylers: [
            { saturation: 0 },
        ]
    }];
    
    var mapOptions = {
        zoom: 15,
        disableDefaultUI: true,
        center: mapCenter
    };
    
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    
    var marker = new google.maps.Marker({
        position: mapMarker,
        map: map,
        title: 'Marker'
    });
    
    var styledMapOptions = {
        map: map,
        name: "Custom"
    }
    
    var customMapType =  new google.maps.StyledMapType(mapStyle,styledMapOptions);
    map.mapTypes.set('custom', customMapType);
    map.setMapTypeId('custom');
}
