// Copyright �2011 Phoenix-Pages.de. All rights reserved.

// Bereich f�r beide Gallerien
var move = true;

function getWindowWidth() { 
	win = window; 
	if (win.innerWidth) { 
		return win.innerWidth; 
	} 
	else { 
		if (win.document.documentElement && 
			win.document.documentElement.clientWidth) { 
			return win.document.documentElement.clientWidth; 
		} 
		return win.document.body.offsetWidth; 
	} 
} 

function getWindowHeight() { 
	win = window; 
	if (win.innerHeight) { 
		return win.innerHeight; 
	} 
	else { 
		if (win.document.documentElement 
			&& win.document.documentElement.clientHeight) { 
			return win.document.documentElement.clientHeight; 
		} 
		return win.document.body.offsetHeight; 
	} 
}

// normale Bildergallery

// Array mit den Bildpfaden
var imgheight = 620;
var navigation = 28;
var img = 0;

var a = new Array();

function deletegallery(){
    $('#gallery').fadeOut('slow', function() {
	$('#gallery-bg').fadeOut('slow', function() {
		move = true;
	});;
    });
}
function showgallery(i, id){
	showImage(i);
	$('#gallery-bg').fadeIn('slow', function() {
		$('#gallery').fadeIn('slow', function() {
			move = false;
		});
	});
}

function loadArray(gid)
{
	a=new Array();
	$.getJSON("/galleryajax/" + gid, function(data){
		$.each(data.items, function(i,item){
			a[i] = new Image();
			a[i].src = '/style/general/img/gallery/'+item;
		});
	});
}

function changeimage(i){
    	if(i==0)
	{
	    if(img>0)
		img--;
	    else
		img=a.length-1;
	}
	else if(i==1)
	{
	    if(img<a.length-1)
		img++;
	    else
		img=0;
	}
	$('#gallery').fadeOut('slow', function() {
	    var width = a[img].width;
	    var height = a[img].height;
	    
	    if(imgheight<height)
	    {
		var p = 100-(((imgheight-100)*100)/a[img].height);
		width = Math.round(a[img].width-((p*a[img].width)/100));
		height = imgheight-120-navigation;
	    }

	    var galleryimg = document.getElementById("galleryimg");
	    galleryimg.src = a[img].src;
	    galleryimg.width = width;
	    galleryimg.height = height;
	    
	    var gallery = document.getElementById("gallery");
	    gallery.style.marginLeft="-"+width/2+"px";
	    gallery.style.width = width+"px";
	    gallery.style.height = height+navigation+"px";
	    
	    $('#gallery').fadeIn('slow', function() { });
	});
}

function showImage(i){
	    var s = a[i];
	    var width = s.width;
	    var height = s.height;
	    img = i;
	    while(img<a.length)
	    {
		if(a[img].src == s.src)
			break;
		else
		{
		    img++;
		}
	    }
	    if(imgheight<height)
	    {
		var p = 100-(((imgheight-100)*100)/s.height);
		width = Math.round(s.width-((p*s.width)/100));
		height = imgheight-120-navigation;
	    }

	    var galleryimg = document.getElementById("galleryimg");
	    galleryimg.src = s.src;
	    galleryimg.width = width;
	    galleryimg.height = height;
	    
	    var gallery = document.getElementById("gallery");
	    gallery.style.marginLeft="-"+width/2+"px";
	    gallery.style.width = width+"px";
	    gallery.style.height = height+navigation+"px";
	    
}



// ------------------------------------------------------------
// Top-Gallery

// Array mit den Bildpfaden
var b= new Array();

b[0] = new Image();
b[0].src = '/style/general/img/top-gallery/img1.jpg';
b[1] = new Image();
b[1].src = '/style/general/img/top-gallery/img2.jpg';
b[2] = new Image();
b[2].src = '/style/general/img/top-gallery/img3.jpg';
b[3] = new Image();
b[3].src = '/style/general/img/top-gallery/img4.jpg';
b[4] = new Image();
b[4].src = '/style/general/img/top-gallery/img5.jpg';
b[5] = new Image();
b[5].src = '/style/general/img/top-gallery/img6.jpg';
b[6] = new Image();
b[6].src = '/style/general/img/top-gallery/img7.jpg';
b[7] = new Image();
b[7].src = '/style/general/img/top-gallery/img8.jpg';

var bild = 0;
var path="";

// Bildwechsel in Millisekunden
var time = 15000;
setInterval('changeimg(1)', time);

// Wechselt das Gallerybild
function changeimg(i)
{
    if(move==true)
    {
	if(i==0)
	{
	    if(bild>0)
		bild--;
	    else
		bild=b.length-1;
	}
	else if(i==1)
	{
	    if(bild<b.length-1)
		bild++;
	    else
		bild=0;
	}
	$('#top-gallery').fadeOut('slow', function() {
	    path="url('"+b[bild].src+"')";
	    document.getElementById("top-gallery").style.backgroundImage=path;
	    $('#top-gallery').fadeIn('slow', function() { });
	});
    }
}





