/* 	QUARANTIME.COM/INTRANET
	Impressum

	Bildungseinrichtung: 	MultiMediaTechnology / FHS
				  Zweck: 	Basisqualifikation (SS10 - QPT1)
				  Autor: 	Ismail Hanli
		 Design/Konzept:	Angelika Bräuml, Wolfgang Schäffer, Lisa-Maria Hofmann
	 
	Special Thanks To Silvia Schneider aka Joana */

var euro = jQuery.noConflict();

var W3CDOM = (document.createElement && document.getElementsByTagName);

var CountdownJahr = 2012;
var CountdownMonat = 12;
var CountdownTag = 21;
var CountdownStunde = 12;
var CountdownMinute = 30;
var CountdownSekunde = 0;

var rating = 0;
var called = false;

euro(document).ready(function(){
	euro("#countdown").each(function(){
		showCountdown();
	});
	
	initFileUploads();
	
	euro("form[class*=news_info] > div").hover(
		function(){
			var newsID =  euro(this).attr("id").substring(4);

			euro("form[class*=news_info] > div[id=news" + newsID + "] > input").each(function(){
				if(euro(this).attr("src") == "/intranet/graphics/point_01.gif" && !called){
					rating++;
				}
			});
			
			called = true;
			
			euro("form[class*=news_info] > div[id=news" + newsID + "] > input").hover(function(){
				euro("form[class*=news_info] > div[id=news" + newsID + "] > input:lt(" + euro(this).attr("value") + ")").attr("src", "/intranet/graphics/point_01.gif");
				euro("form[class*=news_info] > div[id=news" + newsID + "] > input:gt(" + (parseInt(euro(this).attr("value")) - 1) + ")").attr("src", "/intranet/graphics/point_02.gif");
			});
		},
		function(){
			var newsID =  euro(this).attr("id").substring(4);
			
			if(rating == 0){
				euro("form[class*=news_info] > div[id=news" + newsID + "] > input").each(function(){
					euro(this).attr("src", "/intranet/graphics/point_02.gif");
				});
			}
			else{
				euro("form[class*=news_info] > div[id=news" + newsID + "] > input:lt(" + rating + ")").attr("src", "/intranet/graphics/point_01.gif");
				euro("form[class*=news_info] > div[id=news" + newsID + "] > input:gt(" + (rating - 1) + ")").attr("src", "/intranet/graphics/point_02.gif");
			}
			
			rating = 0;
			called = false;
		}
	);
});

function showCountdown()
{

	var Jetzt = new Date();
	var Countdown = new Date(CountdownJahr, CountdownMonat-1, CountdownTag, CountdownStunde, CountdownMinute, CountdownSekunde);
	var MillisekundenBisCountdown = Countdown.getTime()-Jetzt.getTime();
	var Rest = Math.floor(MillisekundenBisCountdown/1000);
	var CountdownText = "";

	if(Rest >= 31536000)
	{
		var Jahre = Math.floor(Rest/31536000);
		Rest = Rest-Jahre*31536000;

		if(Jahre > 1 || Jahre == 0)
		{
		CountdownText += Jahre + " years ";
		}
		else if(Jahre == 1)
		{
			CountdownText += Jahre + " year ";
		}
	}
	if(Rest >= 86400)
	{
		var Tage = Math.floor(Rest/86400);
		Rest = Rest-Tage*86400;

		if(Tage > 1 || Tage == 0)
		{
		CountdownText += Tage + " days ";
		}
		else if(Tage == 1)
		{
			CountdownText += Tage + " day ";
		}
	}
	if(Rest >= 3600)
	{
		var Stunden = Math.floor(Rest/3600);
		Rest = Rest-Stunden*3600;

		if(Stunden > 1 || Stunden == 0)
		{
		CountdownText += Stunden + " hours ";
		}
		else if(Stunden == 1)
		{
			CountdownText += Stunden + " hour ";
		}
	}
	if(Rest >= 60)
	{
		var Minuten = Math.floor(Rest/60);
		Rest = Rest-Minuten*60;

		if(Minuten > 1 || Minuten == 0)
		{
		CountdownText += Minuten + " minutes ";
		}
		else if(Minuten == 1)
		{
			CountdownText += Minuten + " minute ";
		}
	}

	if(Rest > 1 || Rest == 0)
	{
		CountdownText += Rest + " seconds ";
	}
	else if(Rest==1)
	{
		CountdownText += Rest + " second ";
	}

	document.getElementById('countdown').innerHTML = CountdownText;
	window.setTimeout("showCountdown()", 1000);
}

function initFileUploads() {
	if (!W3CDOM) return;
	
	euro("div.fileinputs > input:first-child").addClass("hidden");
	euro("div.fileinputs > input:first-child").css({"z-index":"2", "position":"relative", "margin-top":"20px"});
	euro("<input class='text' /><input type='button' name='SEARCH' value='SEARCH' class='button' /><br />").appendTo(euro("div.fileinputs"));
	euro("div.fileinputs").css({"margin-top":"-25px", "position":"relative"});
	euro("div.fileinputs > input[class=text]").css({"margin-left":"-236px", "margin-top":"25px", "position":"absolute"});
	euro("div.fileinputs > input[class=button]").css({"margin-top":"25px", "margin-left":"-84px", "position":"absolute"});
	euro("div.fileinputs > input:first-child").change(function(){
		euro("div.fileinputs > input[class=text]").attr("value", euro(this).attr("value"));
	});
	
/*	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='/intranet/graphics/button_select.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}*/
}
