//=================================================================
// Yoocms 1.125(c) 
// B2B-WebDesign(tm)
// Inhaber: Alexander Görlich 
// Novalisstr. 7
// 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

var lasturl="---"; 
var currentTemplateType = "";
var strHeadline  = "";
var strmetadescr = "";
var strmetatitle = "";
var strmetakeywords = "";
var strmetadate = "";
var strNews  = "";
var strContent  = "";
var strpicid = "";
var ilang = $("#lang");
var bStaticContent = $('#bStaticContent');
var bLIClick = false;
var domain = "index.php";





$(document).ready(function() 
{
		
	ilang = $("#lang").attr('value');
	bStaticContent = $('#bStaticContent').attr('value');
	init_langSwitch();
	
	var hash = '';

	if(!hash) hash=window.location.hash; 
	
	if (hash == '') 
	{
		window.location.hash = "#cont_id=0";
		hash = "#cont_id=0";
	}
	checkURL(hash);

	$('#nav li a').click(function(){
		var ContId = $(this).attr('value');								  
		bLIClick = true;
		checkURL(this.hash);
//		return false;
	});
	setInterval("checkURL(window.location.hash)",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;
	});
	$('#langRU').click(function()
	{
		var href = $('#langRU').attr('href');
		href += window.location.hash; 
		//alert(href);
		$('#langRU').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)
{
	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 Bilderbox
///   Template Typ 3 = Text 
	var templateType;
	get_TemplateType(hash);
	
/*	$('#col_1').hide('fast');
	$('#col_2').hide('fast');	
	$('#headline').hide('fast');		*/
	$('#load').remove();
	$('#wrapper').append('<span id="load">Lade...</span>');
	$('#load').fadeIn('normal');
				
    switch (currentTemplateType)
	  {
		case "1": { 
					get_metaDescription(hash);
					get_metaTitle(hash);
					get_metaKeywords(hash);	
					get_metaDate(hash);	
					
					get_headline(hash); 
					$('#headline').html(strHeadline );
//					$('.h2').corner("top");
					
					get_content(hash);
					$('#col_1').html(strContent);
					//$("#col_1").corner("bottom");
					$(".yoo_footer").corner("bottom");
					$("#wrapper").corner();					
					$(".yoo_header").corner("top");						
					

					get_news(hash);
					$('#col_2').html(strNews);					
					$("#col_2").corner("br");					
					break 
				}
				
		case "2": { 
					get_metaDescription(hash);
					get_metaTitle(hash);
					get_metaKeywords(hash);	
					get_metaDate(hash);	
					
					get_headline(hash); 
					$('#headline').html(strHeadline );
				//	$('.h2').corner("top");
					
					get_content(hash);
					$('#col_1').html(strContent);
					//$("#col_1").corner("bottom");
					$(".yoo_footer").corner("bottom");
					$("#wrapper").corner();		
					$(".yoo_header").corner("top");		
					
					get_pic(hash);
					$('#col_2').html(make_imageGallery());
					$("#col_2").corner("tr br 5px");
							
			
					//$('#col_2').html(make_imageGallerySlide());			
/*					$("#slider").easySlider({
						auto: true,
						continuous: true 
					});					*/
					break 
				}
				
		case "3": { 
					get_metaDescription(hash);
					get_metaTitle(hash);
					get_metaKeywords(hash);						
					get_metaDate(hash);	
					
					get_headline(hash); 
					$('#headline').html(strHeadline );
				//	$('.h2').corner("top");

					get_content(hash);
					$('#col_1').html(strContent);
					//$("#col_1").corner("bottom");
					$(".yoo_footer").corner("bottom");
					$("#wrapper").corner();					
					$(".yoo_header").corner("top");					
					
					
					$('#col_2').html('');
//					$("#col_2").corner();
					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 += "<div class='set_images'><img id='ImgGal' value=" + ids[i] + " visible =false src=yoo_config/yoo.getcontent.php?action=ShowPic&picid="+  ids[i]  + " /></div>";
				bdone = true;
		};
	};
	output += "<div class='set_button'><input style='padding:2px; width:100px' type='button' value='VOR'  name='vor'  onclick='nextpic()'>";
	output += "<input style='padding:2px; width:100px' type='button' value='ZURÜCK' name='zurück'  onclick='previospic();'></div>";

	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)
{
	//alert("hash in Get Template = " + hash );
	cont_id = hash.replace('#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('#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('#cont_id=',''); 
	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_metaTitle(hash)
{
	cont_id = hash.replace('#cont_id=',''); 
	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_metaKeywords(hash)
{
	cont_id = hash.replace('#cont_id=',''); 
	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('#cont_id=',''); 
	var ret = "";
	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_content(hash)
{
	cont_id = hash.replace('#cont_id=',''); 
	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('#cont_id=',''); 
	

	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')
				{
                                } 
                        }
	});
}
