//=================================================================
// Yoocms 1.0(c) 
// B2B-WebDesign(tm)
// Inhaber: Alexander Görlich 
// Zöttnitz nr. 2
// 07646 Schlöben
// Webadresse http://www.B2B-WebDesign.de
//=================================================================
// ACHTUNG!
// DIESER PROGRAMMCODE IST URHERRECHTLICH GESCHUETZT
// DIE URHEBERRECHTE LIEGEN BEI DEN JEWEILIGEN AUTOREN.
// AENDERUNGEN IN DIESER DATEI ERFOLGEN AUF EIGENE GEFAHR!
// ES IST NICHT GESTATTET, DEN COPYRIGHTHINWEIS ZU AENDERN ODER ZU
// ENTFERNEN. NUR WENN SIE EINE COPYRIGHTHINWEIS-ENTFERNUNG BESTELLT
// HABEN, DUERFEN SIE DIESEN ENTFERNEN.
//================================================================
// BEI FRAGEN WENDEN SIE SICH BITTE AN: KONTAKT@YOOCMS.DE
//=================================================================
// Freie Mitarbeiter:	Stephan Träger 
// Freie Mitarbeiter:	Martin Rautenberg




///   als erstes Template aus aus Datenbank holen
//    Template ist bekannt
///   Überschrift muss immer da sein....
/// 	Keiner gestzt kommt der Master

///   Template Typ 1 = Text newsbox
//    Template Typ 2 = Text 
///   Template Typ 3 = Text Bilderbox


var lasturl="---"; 
var currentTemplateType = "";
var strHeadline  = "";

var strmetatitle = "";
var strmetakeywords = "";
var strmetadescr = "";
var strmetadate = "";
var strStartpage = "";
var dbstartpage = "";

var strNews  = "";
var strContent  = "";
var strpicid = "";
var ilang = $("#lang");
var bStaticContent = $('#bStaticContent');
var bLIClick = false;

var domain = window.location.hostname;
domain = "http://" + domain + "/";





$(document).ready(function() 
{



	ilang = $("#lang").attr('value');
	bStaticContent = $('#bStaticContent').attr('value');
	init_langSwitch();
	
	var hash = '';
//alert ("hashfirst:"+hash);

//martin
	if(!hash) hash=window.location.href; 
//	alert(hash);



if (hash == domain) {
	get_startpage();
	window.location.href = "";
	dbstartpage = strStartpage + "_c0.html";
	window.location.href = dbstartpage;
	}
	

//	checkURL(hash);


	$('#nav li a').click(function(){
		var ContId = $(this).attr('value');								  
		bLIClick = true;
		//alert ("hashsecond:"+hash);
		checkURL(this.hash);
//		return false;
	});
	setInterval("checkURL(window.location.href)",250); 

	
	$('#langDE').click(function()
	{
		var href = $('#langDE').attr('href');
		href += window.location.hash; 
		//alert(href);
		$('#langDE').attr('href',href);
		return true;
	});	
	$('#langEN').click(function()
	{
		var href = $('#langEN').attr('href');
		href += window.location.hash; 
		//alert(href);
		$('#langEN').attr('href',href);
		return true;
	});		

});





function init_langSwitch()
{
	$('#langDE').attr('href', domain + '?lang=1');
	$('#langEN').attr('href', domain + '?lang=2');
	$('#langRU').attr('href', domain + '?lang=3');

}

function checkURL(hash)
{
//alert ("hash_checkURL" + hash);
	if(bStaticContent != "True" || bLIClick )
	{
		if(hash != lasturl && hash != undefined)
		{
		lasturl=hash;
		Weiche(hash);

		} 
	}
}

function Weiche(hash)
{ 
///   Template Typ 1 = Text newsbox
//    Template Typ 2 = Text 
///   Template Typ 3 = Text Bilderbox
	var templateType;
	get_TemplateType(hash);
	$('#load').remove();
	$('#wrapper').append('<span id="load">LOADING...</span>');
	$('#load').fadeIn('fast');
				
    switch (currentTemplateType)
	  {
		case "1": { 
					get_metaTitle(hash);
					get_metaKeywords(hash);
					get_metaDate(hash);
					get_metaDescription(hash);				
					
					get_headline(hash); 
					$('#headline').html(strHeadline );
					
					get_content(hash);
					$('#col_1').html(strContent);
					
					get_news(hash);
					$('#col_2').html(strNews);					
					
					break 
				}
				
		case "2": { 

					get_metaTitle(hash);
					get_metaKeywords(hash);
					get_metaDate(hash);
					get_metaDescription(hash);				
								
					get_headline(hash); 
					$('#headline').html(strHeadline );
					
					get_content(hash);
					$('#col_1').html(strContent);
					
					get_pic(hash);
					$('#col_2').html(make_imageGallery());
					break 
				}
				
		case "3": { 
					get_metaTitle(hash);
					get_metaKeywords(hash);
					get_metaDate(hash);
					get_metaDescription(hash);
					
					get_headline(hash); 
					$('#headline').html(strHeadline );
					
					get_content(hash);
					$('#col_1').html(strContent);
					
					$('#col_2').html('');
					break 

				}
		
		default: { 
					break 
				}
	  }
	
	document.title  = strmetatitle ;
	$('#metaID_Desc').attr('content', strmetadescr );						
	$('#metaID_Key').attr('content', strmetakeywords );						
	$('#metaID_Date').attr('content', strmetadate );						

	$('#load').fadeOut('fast');
/*	$('#col_1').show('fast');
	$('#col_2').show('fast');	
	$('#headline').show('fast');		*/
	$('#temp').attr('class', 'temp_' + currentTemplateType );						
}


function make_imageGallery()
{
	var output = "";
	
	var ids = strpicid.split("/");
	var bdone = false;
	
	for(i = 0; i < ids.length; i++)
	{
		if(ids[i] != "" && !bdone)
		{		
				output += "<img id='ImgGal' value=" + ids[i] + " visible =false src=yoo_config/yoo.getcontent.php?action=ShowPic&picid="+  ids[i]  + " />";
				bdone = true;
		};
	};
	
	output += "<br><input type='button' value='VOR' style='width=200px;height=50px' name='vor'  onclick='nextpic()'>";
	output += "<input type='button' value='ZURÜCK'  style='width=200px;height=50px' name='zurück'  onclick='previospic();'>";


	return output;
}

function make_imageGallerySlide()
{
	var output = "<div id='slider'> <ul>";
	
	var ids = strpicid.split("/");

	
	for(i = 0; i < ids.length; i++)
	{
		if(ids[i] != "" )
		{		
				output += "<li><img id='ImgGal' value=" + ids[i] + " visible =false src=yoo_config/yoo.getcontent.php?action=ShowPic&picid="+  ids[i]  + " /></li>";
				
		};
	};
	
	output += "</li></ul></div>";


	return output;
}

function sleep(ms)
{
	var zeit=(new Date()).getTime();
	var stoppZeit=zeit+ms;
	while((new Date()).getTime()<stoppZeit){};
} 

function nextpic()
{
	var currentPicID = $('#ImgGal').attr('value');

	$('#ImgGal').fadeOut('slow');
	$('#ImgGal').hide('slow');
	var ids = strpicid.split("/");	
	for(i = 0; i < ids.length; i++)
	{
		if ( ids[i] == "" ) 
		{
			ids.splice(i,1);
		}
	}
	var bdone = false;
	for(i = 0; i < ids.length; i++)
	{
		if(ids[i] == currentPicID && !bdone)
		{
				if(i == ids.length-1) 
				{
					$('#ImgGal').attr('src', 'yoo_config/yoo.getcontent.php?action=ShowPic&picid='+  ids[0]);					
					$('#ImgGal').attr('value', ids[0]);					
					bdone = true;
				}
				else
				{
					$('#ImgGal').attr('src', 'yoo_config/yoo.getcontent.php?action=ShowPic&picid=' +  ids[i+1]);
					$('#ImgGal').attr('value', ids[i+1]);					
					bdone = true;					
				}
		};
	};	
	
	sleep(2000);
	//$("#ImgGal").change(function () {
		$('#ImgGal').fadeIn('slow');			
		$('#ImgGal').show('slow');			
	//})
	//.change();
}

function previospic()
{
	var currentPicID = $('#ImgGal').attr('value');
	
	$('#ImgGal').fadeOut('slow');
	$('#ImgGal').hide('slow');	
	var ids = strpicid.split("/");	
	for(i = 0; i < ids.length; i++)
	{
		if ( ids[i] == "" ) 
		{
			ids.splice(i,1);
		}
	}	
	var bdone = false;
	for(i = 0; i < ids.length; i++)
	{
		if(ids[i] == currentPicID)
		{
				if(ids[0] == currentPicID)
				{
					$('#ImgGal').attr('src', 'yoo_config/yoo.getcontent.php?action=ShowPic&picid='+  ids[ids.length-1]);					
					$('#ImgGal').attr('value', ids[ids.length-1]);										
					bdone = true;										
				}
				else
				{
					$('#ImgGal').attr('src', 'yoo_config/yoo.getcontent.php?action=ShowPic&picid=' +  ids[i-1]);
					$('#ImgGal').attr('value', ids[i-1]);															
					bdone = true;										
				}
		};
	};	

	sleep(1000);	
	//$("#ImgGal").change(function () {
			$('#ImgGal').fadeIn('slow');			
			$('#ImgGal').show('slow');						
      //  })
		//.change();


}


function get_TemplateType(hash)
{
//isol
//martin
	//alert("hash in Get Template = " + hash );
//	cont_id = hash.replace('#cont_id=',''); 
cont_id = hash.replace(/.*_c/g,''); 
cont_id = cont_id.replace(/.html.*/g,''); 

//alert ("cont_id:" + cont_id);

	//var data = 'action=GetTempType' + '&contid=' + cont_id + '&lang=1' ;
	var data = 'action=GetTempType' + '&contid=' + cont_id + '&lang=' + ilang ;
	
	var ret = "";
	$.ajax({
		url: "./yoo_config/yoo.getcontent.php",	
		type: "GET",		
		data: data,		
		async: false,		
		cache: false,
		// class Attribute austauschen
		success: function (html) 
				{	
					//alert("templatetype=" + html);
					currentTemplateType  =  html;
				},
		error: function(XMLHttpRequest, textStatus, errorThrown) 
				{ 
					alert(errorThrown);
                    if(textStatus == 'timeout') 
					{
					}
					else if (textStatus == 'error')	
					{
                    } 
                }
	});	
		
}

function get_news()
{
	strNews = "";
	var data = 'action=GetNews' + '&lang=' + ilang ;
	
	$.ajax({
		url: "./yoo_config/yoo.getcontent.php",	
		type: "GET",		
		data: data,		
		async: false,
		cache: false,
		success: function (html) {	
			//alert("return async getnews = " + html);
			strNews  = html;
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) { 
				alert(errorThrown);
                                if(textStatus == 'timeout') 
				{
                                }
				else if (textStatus == 'error')
				{
                                } 
                        }
	});
}

function get_headline(hash)
{
	cont_id = hash.replace(/.*_c/g,''); 
	cont_id = cont_id.replace(/.html.*/g,'');
	//alert ("headlinecontid:"+cont_id);
	var ret = "";
	var data = 'action=GetHeadLine' + '&contid=' + cont_id + '&lang=' + ilang ;
	
	$.ajax({
		url: "./yoo_config/yoo.getcontent.php",	
		type: "GET",		
		data: data,	
		async: false,			
		cache: false,
		success: function (html) {	
			strHeadline  = html;
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) { 
				alert(errorThrown);
                                if(textStatus == 'timeout') 
				{
                                }
				else if (textStatus == 'error')
				{
                                } 
                        }
	});

}

function get_metaDescription(hash)
{
	cont_id = hash.replace(/.*_c/g,''); 
	cont_id = cont_id.replace(/.html.*/g,'');
	var ret = "";
	var data = 'action=GetMetaDescr' + '&contid=' + cont_id + '&lang=' + ilang ;
	
	$.ajax({
		url: "./yoo_config/yoo.getcontent.php",	
		type: "GET",		
		data: data,	
		async: false,			
		cache: false,
		success: function (html) {	
			strmetadescr  = html;
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) { 
				alert(errorThrown);
                                if(textStatus == 'timeout') 
				{
                                }
				else if (textStatus == 'error')
				{
                                } 
                        }
	});

}

function get_metaKeywords(hash)
{
	cont_id = hash.replace(/.*_c/g,''); 
	cont_id = cont_id.replace(/.html.*/g,'');
	var ret = "";
	var data = 'action=GetMetaKeywords' + '&contid=' + cont_id + '&lang=' + ilang ;
	
	$.ajax({
		url: "./yoo_config/yoo.getcontent.php",	
		type: "GET",		
		data: data,	
		async: false,			
		cache: false,
		success: function (html) {	
			strmetakeywords  = html;
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) { 
				alert(errorThrown);
                                if(textStatus == 'timeout') 
				{
                                }
				else if (textStatus == 'error')
				{
                                } 
                        }
	});

}

function get_metaDate(hash)
{
	cont_id = hash.replace(/.*_c/g,''); 
	cont_id = cont_id.replace(/.html.*/g,'');

	var data = 'action=GetMetaDate' + '&contid=' + cont_id + '&lang=' + ilang ;
	
	$.ajax({
		url: "./yoo_config/yoo.getcontent.php",	
		type: "GET",		
		data: data,	
		async: false,			
		cache: false,
		success: function (html) {	
			strmetadate  = html;
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) { 
				alert(errorThrown);
                                if(textStatus == 'timeout') 
				{
                                }
				else if (textStatus == 'error')
				{
                                } 
                        }
	});

}


function get_metaTitle(hash)
{
	cont_id = hash.replace(/.*_c/g,''); 
	cont_id = cont_id.replace(/.html.*/g,'');
	var ret = "";
	var data = 'action=GetMetaTitle' + '&contid=' + cont_id + '&lang=' + ilang ;
	
	$.ajax({
		url: "./yoo_config/yoo.getcontent.php",	
		type: "GET",		
		data: data,	
		async: false,			
		cache: false,
		success: function (html) {	
			strmetatitle  = html;
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) { 
				alert(errorThrown);
                                if(textStatus == 'timeout') 
				{
                                }
				else if (textStatus == 'error')
				{
                                } 
                        }
	});

}

function get_content(hash)
{
	cont_id = hash.replace(/.*_c/g,''); 
	cont_id = cont_id.replace(/.html.*/g,'');

	var data = 'action=GetText' + '&contid=' + cont_id + '&lang=' + ilang ;
	
	$.ajax({
		url: "./yoo_config/yoo.getcontent.php",	
		type: "GET",		
		data: data,		
		async: false,
		cache: false,
		// class Attribute austauschen
		success: function (html) {	
			strContent = html
			//$('#content').html(html);
			//$('#col_1').html(html);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) { 
				alert(errorThrown);
                                if(textStatus == 'timeout') 
				{
                                }
				else if (textStatus == 'error')
				{
                                } 
                        }
	});
}

function get_pic(hash)
{
	cont_id = hash.replace(/.*_c/g,''); 
	cont_id = cont_id.replace(/.html.*/g,'');

	var data = 'action=GetPicIds' + '&contid=' + cont_id ;

		$.ajax({
		url: "./yoo_config/yoo.getcontent.php",	
		type: "GET",		
		data: data,	
		async: false,			
		cache: false,
		success: function (html) {	
				strpicid = html;
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) { 
				alert(errorThrown);
                                if(textStatus == 'timeout') 
				{
                                }
				else if (textStatus == 'error')
				{
                                } 
                        }
	});
}


function get_startpage()
{
	var data = 'action=GetStartpage' + '&startcontid=0&lang=' + ilang ;
	
	$.ajax({
		url: "./yoo_config/yoo.getcontent.php",	
		type: "GET",		
		data: data,		
		async: false,
		cache: false,
		success: function (html) {	
			//alert("return async Startpage = " + html);
			strStartpage  = html;
			
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) { 
				alert(errorThrown);
                                if(textStatus == 'timeout') 
				{
                                }
				else if (textStatus == 'error')
				{
                                } 
                        }
	});
}
