/**
 * @author Zeller Christoph
 * @version 1.0
 * @description main function wordpress theme (jQuery)
 */
var $j = jQuery.noConflict();

$j(document).ready(function() {
	//documentsetter
	if($j('.category-image')) {
		$j('.category-image:not(.active)').css({ opacity: 0.0 });
		setInterval( "slideSwitch()", 5000 );
	}
	if($j('.slideshow-images')) {
		$j('.slideshow-images:not(.active)').css({ opacity: 0.0 });
		$j('.slideshow-thumb').click(function(){
			$j('.slideshow-thumb.active').removeClass('active');
			$j(this).addClass('active');
			
			var href = $j(this).parent().attr('href');
			var last = href.length - 1;
			href = href.substr(1,last);
			slideshow(href);
		});
	}

	initialize();
});

function initialize() {
	var myLatlng = new google.maps.LatLng(48.5577954, 14.4773035);
	var myOptions = {
	  zoom: 10,
	  center: myLatlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("maps"), myOptions);
	
    var contentString = '<div id="content">'+
	    '<div id="siteNotice">'+
	    '</div>'+
	    '<h1 id="firstHeading" class="firstHeading">Gasthof Blumauer</h1>'+
	    '<div id="bodyContent">'+
	    '<p>Marktplatz 8<br />4261 Rainbach</p>'+
	    '<p><a href="http://maps.google.at/?daddr={Marktplatz 8, 4261 Rainbach}" target="_blank">Route berechnen</a></p>'+
	    '</div>'+
	    '</div>';
	    
	var infowindow = new google.maps.InfoWindow({
	    content: contentString
	});
	
	var marker = new google.maps.Marker({
	    position: myLatlng,
	    map: map,
	    title: 'Gasthof Blumauer'
	});
	google.maps.event.addListener(marker, 'click', function() {
	  infowindow.open(map,marker);
	});
}

function slideshow(n) {
	var $active = $j('.slideshow div.active');
	var $next = '.slideshow div.image'+n;
	$next = $j($next);
	//var $next = $j('.slideshow div.image160');
	
	$active.addClass('last-active');
    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1500);
	$j('.last-active').animate({opacity: 0}, 1500, function(){
		$active.removeClass('active last-active');
	});
}

function slideSwitch() {
    var $active = $j('.images img.active');

    if ( $active.length == 0 ) $active = $j('.images img:last');

    var $next =  $active.next().length ? $active.next()
        : $j('.images img:first');

    $active.addClass('last-active');

	//alert($next);

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1200);
		$j('.last-active').animate({opacity: 0}, 1200, function(){
			$active.removeClass('active last-active');
		});
}

