function dgthesis(div) {
	this.div = div;
	this.hoverStatus = 'inactive';
	this.hoverFadeTime = 50; //set time for hover answer-arrows
	this.elementFadeTime = 50; //set time for elements to fade
	this.actColor = 'orange';
	this.css_default_path = null;
	this.cssBackupPath;
	this.homepage = false;

	this.render = function(){
	
		this.addMouseCursor();
		this.checkIfHomgepage();
		this.setImageVars();
		this.addEventHandler(); 
		
		if(!(this.getCookieStatus())){
			this.changeColors('white');
		}	
	}
	
	
	this.addMouseCursor = function(){
		//change cursor state for interactive elements
		this.div.find('#thesis-choice-answer-positive').css('cursor', 'pointer');
		this.div.find('#thesis-choice-answer-negative').css('cursor', 'pointer');
	}
	
	this.setImageVars = function(){
		if(this.actColor == 'white' && myThesis.homepage == true){
			if (navigator.userAgent.indexOf('MSIE') > 0) {
				this.choiceAnswerPositiveImageOver = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-over_white.jpg)';
				this.choiceAnswerPositiveImageUnder = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-under_white.jpg)';
				this.choiceAnswerNegativeImageOver = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-over_white.jpg)';
				this.choiceAnswerNegativeImageUnder = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-under_white.jpg)';
				this.div.find('#thesis-choice-answer-positive-image').attr('src', '/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-over_white.jpg');
				this.div.find('#thesis-choice-answer-negative-image').attr('src', '/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-over_white.jpg');
			}else{
				this.choiceAnswerPositiveImageOver = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-over_white.png)';
				this.choiceAnswerPositiveImageUnder = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-under_white.png)';
				this.choiceAnswerNegativeImageOver = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-over_white.png)';
				this.choiceAnswerNegativeImageUnder = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-under_white.png)';
				this.div.find('#thesis-choice-answer-positive-image').attr('src', '/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-over_white.png');
				this.div.find('#thesis-choice-answer-negative-image').attr('src', '/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-over_white.png');
			}
		}else{
		    if (navigator.userAgent.indexOf('MSIE') > 0) {
				this.choiceAnswerPositiveImageOver = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-over.jpg)';
		    	this.choiceAnswerPositiveImageUnder = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-under.jpg)';
		    	this.choiceAnswerNegativeImageOver = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-over.jpg)';
		    	this.choiceAnswerNegativeImageUnder = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-under.jpg)';
		    	this.div.find('#thesis-choice-answer-positive-image').attr('src', '/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-over.jpg');
				this.div.find('#thesis-choice-answer-negative-image').attr('src', '/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-over.jpg');
			}else{
				this.choiceAnswerPositiveImageOver = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-over.png)';
		    	this.choiceAnswerPositiveImageUnder = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-under.png)';
		    	this.choiceAnswerNegativeImageOver = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-over.png)';
		    	this.choiceAnswerNegativeImageUnder = 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-under.png)';
		    	this.div.find('#thesis-choice-answer-positive-image').attr('src', '/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-over.png');
				this.div.find('#thesis-choice-answer-negative-image').attr('src', '/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-right-over.png');
			}
		}
	}
	
	
	this.addEventHandler = function(){
		// add click events
			this.div.find('#thesis-choice-answer-positive').click(function() {
				if (myThesis.hoverStatus == 'inactive') {
					myThesis.showAnswer('positive');
				}
			});
			
			this.div.find('#thesis-choice-answer-negative').click(function() {
				if (myThesis.hoverStatus == 'inactive') {
					myThesis.showAnswer('negative');
				}
			});
		// -
		
		
		//set hover events
			this.div.find('#thesis-choice-answer-positive').hover(
				function() {
					myThesis.hoverStatus = 'active';
					myThesis.hoverChoice('in', 'positive');
				},
				function() {
					myThesis.hoverChoice('out', 'positive');
				}
			);
			
			this.div.find('#thesis-choice-answer-negative').hover(
				function() {
					myThesis.hoverStatus = 'active';
					myThesis.hoverChoice('in', 'negative');
				},
				function() {
					myThesis.hoverChoice('out', 'negative');
				}
			);
		// -
		
		// Back-Button
			this.div.find('#thesis-back-button').click(function() {
				myThesis.resetThesis();
			});
		// -
	}
	
	this.checkIfHomgepage = function(){
		$('link').each(function(index) {
		    if($(this).attr('rel').indexOf('stylesheet') != 1){
			    			    	
			    if($(this).attr('title') == 'Alternative'){
			    	myThesis.homepage = true;
			    }
			}
		});
	}
	
	this.getCookieStatus = function(){
		//check if thesis has been answered
		var checkCookieStatus = document.cookie.split(';');
		
		var counter = 0;
		
		$(checkCookieStatus).each(function(index, item) {
		    if (item != ' thesisAnswered=yes') {
				counter++;
			}
	 	});
	 	if (counter == checkCookieStatus.length) {
			return false;
		}else{
	 		return true;
		}
	}
	
	this.resetThesis = function(){
	
		//set click event
			//this.addEventHandler();
			this.div.find('#thesis-choice-answer-positive').click(function() {
				if (myThesis.hoverStatus == 'inactive') {
					myThesis.showAnswer('positive');
				}
			});
			
		//change elements
			if(this.div.find('#thesis-answer-positive').css('display') == 'inline') {
				this.div.find('#thesis-choice-answer-positive').fadeOut(this.elementFadeTime, function() {
						myThesis.div.find('#thesis-choice-answer-positive').css('backgroundImage', myThesis.choiceAnswerPositiveImageUnder);
		    			myThesis.div.find('#thesis-choice-answer-positive').fadeIn(myThesis.elementFadeTime);
		    			myThesis.hoverStatus = 'inactive';
		    	});
		    	
				this.div.find('#thesis-answer-positive').fadeOut(this.elementFadeTime, function() {
		    		myThesis.div.find('#thesis-main').fadeIn(myThesis.elementFadeTime);
		    		myThesis.div.find('#thesis-choice-answer-negative').fadeIn(myThesis.elementFadeTime);
		    	});
			}
			
			if(this.div.find('#thesis-answer-negative').css('display') == 'inline') {
				this.div.find('#thesis-answer-negative').fadeOut(this.elementFadeTime, function() {
					myThesis.div.find('#thesis-choice-answer-negative').css('backgroundImage', myThesis.choiceAnswerNegativeImageUnder);
		    		myThesis.div.find('#thesis-main').fadeIn(myThesis.elementFadeTime);
		    		myThesis.div.find('#thesis-choice-answer-negative').fadeIn(myThesis.elementFadeTime);
		    	});
		    	
		    	this.div.find('#thesis-choice-answer-alternative').fadeOut(this.elementFadeTime, function() {
		    		myThesis.div.find('#thesis-choice-answer-positive').fadeIn(myThesis.elementFadeTime);
		    	});
			}
			
			this.div.find('#thesis-back-button').fadeOut(this.elementFadeTime);
	}



	this.showAnswer = function(status){
		this.div.find('#thesis-choice-answer-positive-image-container').css('display' , 'none');
		this.div.find('#thesis-choice-answer-negative-image-container').css('display' , 'none');
	
		
    	//set cookie to answered
    		document.cookie = 'thesisAnswered=yes';
    	
    	//remove click event
    		this.div.find('#thesis-choice-answer-positive').unbind('click');
    		
    	//change elements

    		this.div.find('#thesis-back-button').fadeIn(this.elementFadeTime);
    		this.div.find('#thesis-choice-answer-negative').fadeOut(this.elementFadeTime);
    		
    		if (status == 'positive') {
    		    		
    			this.div.find('#thesis-main').fadeOut(this.elementFadeTime, function() {
    				myThesis.div.find('#thesis-answer-positive').fadeIn(myThesis.elementFadeTime, function() {
    	    			myThesis.div.find('#thesis-answer-positive').css('display', 'inline');
    	    			myThesis.div.find('#thesis-choice-answer-positive').css('backgroundImage', myThesis.choiceAnswerPositiveImageOver);
    	    		});
    	    	});
    		}
    		
    		if (status == 'negative') {
    			this.div.find('#thesis-main').fadeOut(this.elementFadeTime, function() {
    				myThesis.div.find('#thesis-answer-negative').fadeIn(myThesis.elementFadeTime, function() {
    	    			myThesis.div.find('#thesis-answer-negative').css('display', 'inline');
    	    		});
    	    	});

    	    	this.div.find('#thesis-answer-positive').fadeOut(this.elementFadeTime, function() {
    	    		myThesis.div.find('#thesis-choice-answer-alternative').fadeIn(myThesis.elementFadeTime);
    	    		if (navigator.userAgent.indexOf('MSIE') > 0) {
    	    			myThesis.div.find('#thesis-choice-answer-alternative').css('backgroundImage', 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-over.jpg)');
    	    		}else {
    	    			myThesis.div.find('#thesis-choice-answer-alternative').css('backgroundImage', 'url(/fileadmin/templates/dialoggestalter.de/img/thesis_bg_arrow-left-over.png)');
    	    		
    	    		}
    	    	});
    		}
    		
    	//change Color
    		this.changeColors('orange');
	}


	this.hoverChoice = function(direction, choice){
	//change bg-images
	
	
		if (this.div.find('#thesis-main').css('display') != 'none') {
			if (direction == 'in' && choice == 'positive') {
			   	this.setTempImg(this.div.find('#thesis-choice-answer-positive-image-container'));
			
				this.div.find('#thesis-choice-answer-positive').fadeOut(this.hoverFadeTime, function() {
	    			myThesis.div.find('#thesis-choice-answer-positive').css('backgroundImage' ,myThesis.choiceAnswerPositiveImageOver);
	    			
	    			myThesis.div.find('#thesis-choice-answer-positive').fadeIn(myThesis.hoverFadeTime,function(){
	    				myThesis.hoverStatus = 'inactive';
	    			});
	    		});
			}
			
			if (direction == 'out' && choice == 'positive') {
				this.div.find('#thesis-choice-answer-positive').fadeOut(this.hoverFadeTime, function() {
	    			myThesis.div.find('#thesis-choice-answer-positive').css('backgroundImage' ,myThesis.choiceAnswerPositiveImageUnder);
					myThesis.div.find('#thesis-choice-answer-positive').fadeIn(myThesis.hoverFadeTime);
	    			
	    			myThesis.removeTempImg(myThesis.div.find('#thesis-choice-answer-positive-image-container'));
	    		});
			}
			
			
			
			if (direction == 'in' && choice == 'negative') {
			   	this.setTempImg(this.div.find('#thesis-choice-answer-negative-image-container'));

				this.div.find('#thesis-choice-answer-negative').fadeOut(this.hoverFadeTime, function() {
	    			myThesis.div.find('#thesis-choice-answer-negative').css('backgroundImage' ,myThesis.choiceAnswerNegativeImageOver);
	    			
	    			myThesis.div.find('#thesis-choice-answer-negative').fadeIn(myThesis.hoverFadeTime,function(){
	    				myThesis.hoverStatus = 'inactive';
	    			});
	    		});
			}
			
			if (direction == 'out' && choice == 'negative') {
				this.div.find('#thesis-choice-answer-negative').fadeOut(this.hoverFadeTime, function() {
	    			myThesis.div.find('#thesis-choice-answer-negative').css('backgroundImage' ,myThesis.choiceAnswerNegativeImageUnder);
					myThesis.div.find('#thesis-choice-answer-negative').fadeIn(myThesis.hoverFadeTime);
	    			
	    			myThesis.removeTempImg(myThesis.div.find('#thesis-choice-answer-negative-image-container'));
	    		});
			}
			
		}
		
	}
	
	this.setTempImg = function(imgContainer) {
   		jQuery(imgContainer).fadeIn(this.hoverFadeTime);
	}

	this.removeTempImg = function(imgContainer) {
		jQuery(imgContainer).fadeOut(this.hoverFadeTime);
	}
	
	
	this.changeColors = function(colorChangeTo) {
	
		if(this.actColor == colorChangeTo){
			// Nothing todo....
			return;
		}
	
		// get CSS files
			var css_default,css_alt = null;
		
			$('link').each(function(index) {
			    if($(this).attr('rel').indexOf('stylesheet') != 1){
			    	
			    	if($(this).attr('title') == 'Standard'){
			    		css_default = $(this);
			    		//alert(css_default.attr('href')+' '+$(this).attr('href'));
			    	}
			    	
			    	if($(this).attr('title') == 'Alternative'){
			    		css_alt = $(this);
			    		myThesis.cssBackupPath = css_alt.attr('href');
			    		myThesis.homepage = true;
			    	}
			    }
			});
			
			
		// -
		
		
		this.actColor = colorChangeTo;
		this.setImageVars();
		
		
		if(colorChangeTo == 'white' && myThesis.homepage == true){
				
			//change of logo image now in css (display: none)		
			//$('#logoImage').attr('src', 'http://dialoggestalter.steuerungb.de/fileadmin/templates/dialoggestalter.de/img/logo-dialoggestalter_white.png');
			
			myThesis.changeTeasermenuMoreLinkImage(colorChangeTo);
		
			this.css_default_path = css_default.attr('href');
			css_default.attr('href', css_alt.attr('href'));
			/* from jQuery
			// convert the value to a string (all browsers do this but IE) see #1070
			elem.setAttribute( name, "" + value );
			// note: works in IE, but stops after completion -> must start at last position // sry, found no other way
			*/
		}else if(myThesis.homepage == true){
			jQuery('body').fadeOut(0, function(){
			    css_default.attr('href', myThesis.css_default_path);
			
				//change of logo image now in css (display: none)
				//$('#logoImage').attr('src', 'http://dialoggestalter.steuerungb.de/fileadmin/templates/dialoggestalter.de/img/logo-dialoggestalter.png');
				
				myThesis.changeTeasermenuMoreLinkImage(colorChangeTo);

			}.apply(css_default));
			jQuery('body').fadeIn('slow');
		}
	}
	
	this.changeTeasermenuMoreLinkImage = function(colorChangeTo) {
		var arrTeasermenuMoreLinkImage = document.getElementsByTagName('img');
	
		for (i=0; i < arrTeasermenuMoreLinkImage.length; i++) {
			var elementImg = arrTeasermenuMoreLinkImage[i];
			
			//note getAttribute('class') does not work in IE7
			//if (elementImg.getAttribute('class') == 'teasermenu-morelink-image' && colorChangeTo == 'white') {
			if (elementImg.className == 'teasermenu-morelink-image' && colorChangeTo == 'white') {
				elementImg.src = 'fileadmin/templates/dialoggestalter.de/img/teaser-menu_btn_more-link_white.png';
			}
		
			//if (elementImg.getAttribute('class') == 'teasermenu-morelink-image' && colorChangeTo == 'orange') {
			if (elementImg.className == 'teasermenu-morelink-image' && colorChangeTo == 'orange') {
				elementImg.src = 'fileadmin/templates/dialoggestalter.de/img/teaser-menu_btn_more-link_orange.png';
			}
		}
		
		var arrFooterDirectAccessButton = document.getElementsByTagName('input');
		
		for (i=0; i < arrFooterDirectAccessButton.length; i++) {
			var elementInput = arrFooterDirectAccessButton[i];
			
			//if (elementInput.getAttribute('class') == 'button' && colorChangeTo == 'white') {
			if (elementInput.className == 'button' && colorChangeTo == 'white') {
				elementInput.src = 'fileadmin/templates/dialoggestalter.de/img/button_white.png';
			}
			
			//if (elementInput.getAttribute('class') == 'button' && colorChangeTo == 'orange') {
			if (elementInput.className == 'button' && colorChangeTo == 'orange') {
				elementInput.src = 'fileadmin/templates/dialoggestalter.de/img/button_orange.png';
			}	
			
			//if (elementInput.getAttribute('class') == 'submit' && colorChangeTo == 'white') {
			if (elementInput.className == 'submit' && colorChangeTo == 'white') {
				elementInput.src = 'fileadmin/templates/dialoggestalter.de/img/search_submit_button_white.png';
			}
			
			//if (elementInput.getAttribute('class') == 'submit' && colorChangeTo == 'orange') {
			if (elementInput.className == 'submit' && colorChangeTo == 'orange') {
				elementInput.src = 'fileadmin/templates/dialoggestalter.de/img/search_submit_button.png';
			}	
		}
	}
}

var myThesis;

jQuery(document).ready(function(){
	myThesis = new dgthesis($('.thesis-output-container'));
	myThesis.render();
});


//resetThesis -> falschen Bezug entfernt
//resetThesis -> nicht mehr komplette funktion addEventHandler, sondern nur einzelner Handler hinzugef�gt (gab sonst eine Endlosschleife im IE)
//changeColors -> Logo bei white richtig eingebaut
//getCookieStatus -> umgestellt
//changeTeasermenuMoreLinkImage -> eingebaut
