// -----------------------------------------------------------------------------------
//
// Based on code by Scott Upton, strongly changed for his own purpose by Boris Eder
// http://www.b0ris.com
//
// This work is licensed under a Creative Commons License
// Attribution-ShareAlike 2.0
// http://creativecommons.org/licenses/by-sa/2.0/
//
// Associated APIs copyright their respective owners
//
// -----------------------------------------------------------------------------------
// --- version date: 26/10/06 --------------------------------------------------------


// Photo directory for this gallery
var photoDir = "bilder/";
var spezialURL ="img/spezial";

// Number of photos in this gallery
var photoNum = photoArray.length;

// if no photoId supplied then set default
var photoId = (!photoId)? 0 : photoId;

// tracks which section is active
var wherearewe = (!photoId)? "Home" : "Portfolio";
/*--------------------------------------------------------------------------*/

// Additional methods for Element added by SU, Couloir
Object.extend(Element, {
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});
/*--------------------------------------------------------------------------*/

var Slideshow = Class.create();

Slideshow.prototype = {
	initialize: function(photoId) {
		this.photoId = photoId;
		this.photo = 'Photo';
		this.loader = 'Loader';
		this.photoBox = 'Container';
		this.prevLink = 'PrevLink';
		this.nextLink = 'NextLink';
		this.caption = 'Caption';

		this.steuerung = 'LinkContainer';
		this.inhalte = 'Inhalt';
		this.inhalte2 = 'Inhalt2';
	},
	setNewPhotoParams: function() {
		
        Element.setInnerHTML(this.caption,photoArray[photoId][1]);
    //  Element.setHref(this.prevLink, "#" + (photoId+1));
	//	Element.setHref(this.nextLink, "#" + (photoId+1));
	},
    nextPhoto: function(){
        if(photoId == photoEnd) photoId = (photoStart-1); //loop
        (photoId == (photoArray.length - 1)) ? photoId = 0 : photoId++;
        this.Fader();    
    },
	prevPhoto: function(){
        (photoId == 0) ? photoId = photoArray.length - 1 : photoId--;
        this.Fader();
    },
//  Function for Slidewhow
    Fader: function() {
        element=$(this);
        this.setNewPhotoParams();
        new Effect.Fade(element.photo,
        {
        duration: 1,
        afterFinish: function(){
            Element.setSrc(element.photo,photoDir + photoArray[photoId][0]);
            Element.show(element.photo); 

            Element.show('Caption');
            Element.show('PrevLink');
            Element.show('NextLink');
            },
        beforeStart:function(){
            Element.setSrc(element.loader,photoDir + photoArray[photoId][0]);
            Element.show(element.loader); 
        
            Element.hide('Caption');
            Element.hide('PrevLink');
            Element.hide('NextLink');
            }
        })
    },
//  Function for Slideshow
    initSwap: function() {
        this.setNewPhotoParams();
        Element.setSrc(this.photo,photoDir + photoArray[photoId][0]);
        Element.show(this.caption);
        Element.show(this.steuerung);

        new Effect.Appear(this.photo);
    },
    faderSpezial: function(spezialId) {
    element=$(this);

    new Effect.Fade(element.photo,
    {
    duration: 1,
    afterFinish: function(){
        Element.setSrc(element.photo, spezialURL + spezialId + ".jpg");
        Element.show(element.photo); 

        Element.show('PrevLink');
        Element.show('NextLink');
        },
    beforeStart:function(){
        Element.setSrc(element.loader, spezialURL + spezialId + ".jpg");
        Element.show(element.loader); 
        
        Element.hide('PrevLink');
        Element.hide('NextLink');
        }
    })
    },
    loadMachine: function(auswahl) {
    
    element=$(this);
    this.hider();
    
    switch(auswahl) {
            case "Home": 
                new Effect.Appear(this.inhalte, {
                    beforeStart:function(){
                    Element.setInnerHTML(element.inhalte,"<p class='start_slogan1'>gelungenes design entsteht aus der kombination von umfangreicher wahrnehmung,</p><p class='start_slogan2'>kreativit&auml;t, wissen, leidenschaft und dem wunsch nach &auml;sthetischem bewusstsein.</p>");
                    Element.setInnerHTML(element.inhalte2,"<img src='img/mpd_home.gif' alt='marthaploderdesign'/>");
                    },
                    afterFinish:function(){

                    new Effect.Fade(element.inhalte, {
                        delay: 4,
                        duration: 1,
                            afterFinish: function(){
                            new Effect.Appear(element.inhalte2, {
                        delay: 0,
                        duration: 1});
                            }})}});
            break;
            case "News":
Element.setInnerHTML(this.inhalte2, "<p class='news2'><a href='#' onclick='kundenLink(0,3);'>petra raab's wundert&uuml;te</a><p class='news3'><a href='#' onclick='kundenLink(9,10);'>nikolaus lehner</a></p><p class='news4'><a href='#' onclick='kundenLink(11,12);'>kirchenwirt lienz</a></p>");
                new Effect.Appear(this.inhalte2, {delay:0.5});
            break;
            case "Kunden":
Element.setInnerHTML(this.inhalte2, "<p class='kundenliste'><a href='#' onclick='kundenLink(61,62);'>chefmen&uuml;</a><br/><a href='#' onclick='kundenLink(56,57);'>claudia brunnarius</a><br/><a href='#' onclick='kundenLink(58,60);'>da vitti</a><br/><a href='#' onclick='kundenLink(76,79);'>elfriede weber</a><br/><a href='#' onclick='kundenLink(65,69);'>eskimo</a><br/><a href='#' onclick='kundenLink(90,90);'>heller wiener zuckerl</a><br/><a href='#' onclick='kundenLink(45,48);'>heissenberger</a><br/><a href='#' onclick='kundenLink(31,44);'>iglo</a><br/><a href='#' onclick='kundenLink(49,55);'>ja! nat&uuml;rlich</a><br/><a href='#' onclick='kundenLink(11,12);'>kirchenwirt lienz</a><br/><a href='#' onclick='kundenLink(26,27);'>kotanyi</a><br/><a href='#' onclick='kundenLink(13,13);'>kunstnetzwerk</a><br/><a href='#' onclick='kundenLink(91,94);'>lexus</a><br/><a href='#' onclick='kundenLink(71,71);'>list</a><br/><a href='#' onclick='kundenLink(14,17);'>michael inmann</a><br/><a href='#' onclick='kundenLink(4,8);'>moses afanyi</a><br/><a href='#' onclick='kundenLink(9,10);'>nikolaus lehner</a><br/><a href='#' onclick='kundenLink(0,3);'>petra raab's wundert&uuml;te</a><br/><a href='#' onclick='kundenLink(86,89);'>rauch cafemio</a><br/><a href='#' onclick='kundenLink(70,70);'>rauch fresh</a><br/><a href='#' onclick='kundenLink(63,64);'>rauch green tea</a><br/><a href='#' onclick='kundenLink(28,30);'>rauch nativa</a><br/><a href='#' onclick='kundenLink(72,75);'>sirius</a><br/><a href='#' onclick='kundenLink(80,85);'>vitalinea</a><br/><a href='#' onclick='kundenLink(18,27);'>wini brugger</a><br/></p>");
                new Effect.Appear(this.inhalte2, {delay:0.5});
            break;
            case "Spezial": 
                new Effect.Appear(this.photo, {
                    beforeStart:function(){
                        Element.setSrc(element.photo, spezialURL + spezialId + ".jpg");
                        Element.setInnerHTML(element.inhalte2,"<p class='captioninbox'>freie arbeiten aus ton</p>");

                    },
                    afterFinish:function(){
                        Element.show(element.inhalte2);
}});
            break;
            case "Kontakt":    
                new Effect.Appear(this.inhalte, {
                    beforeStart:function(){
                    Element.setInnerHTML(element.inhalte,"<img src='img/buero.jpg' alt='Atelier'/>");
                    Element.setInnerHTML(element.inhalte2,"<div class='portrait'><img src='img/martha.jpg' alt='Foto von Martha Ploder'/></div><p class='kontakt1'>martha ploder design l eslarngasse 10 l 3a l 1030 wien</p><p class='kontakt2'> tel +43 664 4630121 l <a href='mailto:office@marthaploder-design.at' alt='E-Mail an Martha'>office@marthaploder-design.at</a></p>");
                    },
                    afterFinish:function(){
                        new Effect.Fade(element.inhalte, {
                        delay: 4,
                        duration: 1,
                        afterFinish: function(){
                            new Effect.Appear(element.inhalte2, {
                        delay: 0,
                        duration: 1});
                            }})}});
					break;
        }
    },
    hider: function() {
        Element.hide(this.caption);
        Element.hide(this.photo);
        Element.hide(this.loader);
        Element.hide(this.steuerung);
        Element.hide(this.inhalte);
        Element.hide(this.inhalte2);
    }
}

/*--------------------------------------------------------------------------*/

// Establish CSS-driven events via Behaviour script
var myrules = {
	'#PrevLink' : function(element){
		element.onclick = function(){

			photoStart = 100;
			photoEnd = 100;

			var myPhoto = new Slideshow(photoId);
            
            if (wherearewe == "Spezial") {
                (spezialId != 1) ? spezialId-- : spezialId=3;
                myPhoto.faderSpezial(spezialId);
                window.clearTimeout(aktiv);
            }
            else {
                myPhoto.prevPhoto();
                // when user takes over control, slideshow should stop
                window.clearTimeout(aktiv);
            }}
	},
	'#NextLink' : function(element){
		element.onclick = function(){
			
			photoStart = 100;
			photoEnd = 100;
			
			var myPhoto = new Slideshow(photoId);

            if (wherearewe == "Spezial") {
                (spezialId == 3) ? spezialId=1 : spezialId++;
                myPhoto.faderSpezial(spezialId);
                window.clearTimeout(aktiv);
            }
            else {
                myPhoto.nextPhoto();
                // when user takes over control, slideshow should stop
                window.clearTimeout(aktiv);
            }
		}
	},
	'#Home' : function(element){
		element.onclick = function(){
            var auswahl ="Home";
            
            // Stop Portfolio-Slideshow
            window.clearTimeout(aktiv);

            var myPhoto = new Slideshow(photoId);
            myPhoto.loadMachine(auswahl);

            wherearewe = auswahl;
            checkplace();
            }
    },
	'#News' : function(element){
        element.onclick = function(){
            var auswahl = "News"   
            document.getElementById("CaptionContainer").style.display = "inline";
            window.clearTimeout(aktiv);

            var myPhoto = new Slideshow(photoId);
            myPhoto.loadMachine(auswahl);
        
            wherearewe = auswahl;
            checkplace();
            }
    },

	'#Portfolio' : function(element){
		element.onclick = function(){
        
        	document.getElementById("CaptionContainer").style.display = "inline";
kundenLink(0,photoNum);            }
    },
	'#Kunden' : function(element){
        element.onclick = function(){
            var auswahl = "Kunden"   
            document.getElementById("CaptionContainer").style.display = "inline";
            window.clearTimeout(aktiv);

            var myPhoto = new Slideshow(photoId);
            myPhoto.loadMachine(auswahl);
        
            wherearewe = auswahl;
            checkplace();
            }
    },
	'#Spezial' : function(element){
		element.onclick = function(){
            var auswahl = "Spezial"   

        	var myPhoto = new Slideshow(photoId);
            myPhoto.loadMachine(auswahl);
        
            document.getElementById("CaptionContainer").style.display = "inline";
            window.clearTimeout(aktiv);
            wherearewe = auswahl;
            checkplace();
            aktiv = window.setTimeout("warten()", 5000);
            }
    },
	'#Kontakt' : function(element){
		element.onclick = function(){
            var auswahl = "Kontakt"   
            
            var myPhoto = new Slideshow(photoId);
            myPhoto.loadMachine(auswahl);

            document.getElementById("CaptionContainer").style.display = "inline";
        
            window.clearTimeout(aktiv);
            wherearewe = auswahl;
            checkplace();
        }
    },
    a : function(element){
    element.onfocus = function(){
        this.blur();
	}}
};
    
var auswahl = "Home";
	var spezialId = 1;
	var photoEnd = 100;
	var photoStart = 100;

// Add window.onload event to initialize
Behaviour.addLoadEvent(init);
Behaviour.apply();
function init() {
        bilderVorladen();
        checkplace();

        //Initialize aktiv as variable
        aktiv = window.setTimeout("", 10);
        document.getElementById('Inhalt').innerHTML = "<img src='img/mpd_home.gif' alt='marthaploderdesign'/>";

        var myPhoto = new Slideshow(photoId);
        myPhoto.hider();
        myPhoto.loadMachine(auswahl);
}

function kundenLink(targetStart, targetEnd) {

        	var myPhoto = new Slideshow(photoId);
            myPhoto.hider();
            photoId = targetStart;
            photoStart = targetStart;
            photoEnd = targetEnd;
            
            myPhoto.initSwap();
            aktiv = window.setTimeout("warten()", 5000);
            wherearewe = "Portfolio";
            checkplace();
    }

function warten() {
    var myPhoto = new Slideshow(photoId); 
    var start
    
    if (wherearewe == "Spezial") {
        (spezialId == 3) ? spezialId = 1 : spezialId++;

        myPhoto.faderSpezial(spezialId);
        aktiv = window.setTimeout("warten()", 5000);
    }
    else {
        myPhoto.nextPhoto();
        aktiv = window.setTimeout("warten()", 5000);
    }
}

function checkplace() {
    document.getElementById("Home").style.color = "#999";
    document.getElementById("News").style.color = "#999";
    document.getElementById("Portfolio").style.color = "#999";
    document.getElementById("Kunden").style.color = "#999";
    document.getElementById("Spezial").style.color = "#999";
    document.getElementById("Kontakt").style.color = "#999";		
    document.getElementById(wherearewe).style.color = "#333";
}
