
/*
	Javascript
*/

//save data of current section
function Doc(storyid, lang){
	Doc.language = lang;
	Doc.storyID = storyid;
}
Doc.storyID = 0;
Doc.language = '';




/* Navigation Produktinhalt */
function ProductNavi(){
	this.changestyleclass = "";

	this.init = function(){
		$("#maincontent .navi a").click(this.linkclick);
		var currentselected = $("#maincontent .navi a[class=selected]");
		this.hideAll();
		$(currentselected).click();
		
		this.changeStyle(this.changestyleclass);
	}
	this.linkclick = function(){
		productnavi.unselectall();
		productnavi.showhideContainer(this, true)
	}
	this.unselectall = function(){
		$("#maincontent .navi a.selected").each(function(){
			productnavi.showhideContainer(this, false);
		});
	}
	this.hideAll = function(){
		$("#maincontent .navi a").each(function(){
			productnavi.showhideContainer(this, false);
		});
	}
	this.showhideContainer = function(button, show){
		var id = $(button).attr("id");
		if(show){			
			$("#"+id+"_content").show();
			$(button).addClass("selected");
		}else{
			$(button).removeClass("selected");
			$("#"+id+"_content").hide();
		}
	}
	this.changeStyle = function(styleclass){
		this.changestyleclass = styleclass;
		$('#pagecontent').attr('class',this.changestyleclass);
	}
}

var productnavi = new ProductNavi();




/* Linkte Navigation */

function ProductIndexNavi(){
	this.init = function(){
		$('#productindex .navi a').click(this.showchilds);
	}
	this.showchilds = function(){
		/* close all other */
		$('#productindex .navi a').removeClass("selected");

		$(this).addClass("selected");
		var group = $(this).next();
		group.show("slow");
	}
	this.init();
}




/* 
	setup for highlight fade in fade out animation
*/
$.fn.cycle.defaults.speed   = 900;
$.fn.cycle.defaults.timeout = 6000;

$('#fade').cycle({ 
    fx:    'fade', 
    speed:  1500 
 });


$(document).ready(function(){

	productnavi.init();
	ProductIndexNavi();
	Keyword.init();

	/* Suche */
	$("#search").val("");
	$("#search").blur(function(){
			if($(this).val().length == 0){
				$(this).removeClass("focus");
			}		
			else{
				$("#SearchDoc").submit();
			}
			$(this).css("width",80);
	});	
	$("#search").focus(function(){
		$(this).addClass("focus");	
		$(this).css("width",120);
	});


	//switch image function
	$("img[hoversrc]").each(function(){

		$(this).mouseover(function(){
			$(document).attr("lastmover",$(this).attr("src"));
			$(this).attr("src",$(this).attr("hoversrc"));
		});
		$(this).mouseout(function(){
			$(this).attr("src",$(document).attr("lastmover"));
		});
	});
	
	$("#OpenProductCompare").click(function(){
		OpenCompareWindow($(document).attr("language"));
	});
	
	//inputs with openPage Handler
	/*
	$('input[openPage]').click(funtion(){
	});
	*/
	
	$("input[openPopup]").click(function(){
		switch($(this).attr('openPopup')){
			case 'comparePSU':
				ComparePSU($(this).attr('openPopupParam'));
				break;
			case 'compareFAN':
				CompareFAN($(this).attr('openPopupParam'));
				break;
			case 'OpenPrint':
				OpenPrint($(this).attr('openPopupParam'));
				break;
		}
	});
//BigImageContainer
	$("input[bigimage]").click(function(){
		var url = $(this).attr('bigimage');
		BigImageContainer.show(this, url, $(this).attr('bigimage_text'));
	});

	
});


/*
	lexicon keyword connection
*/

function Keyword(){}
Keyword.init = function(){
	$('a[class=keyword]').click(Keyword.click);
}

Keyword.click = function(e){
	e.preventDefault();
	Popup.openByPreset($(this).attr('href'), 'keyword');
}

/*
	overlay image container
*/
document.onkeyup = function(e){
	if (!e)
    		e = window.event;

  	if(e.keyCode == 27){
		//esc
		BigImageContainer.close(null);
	}
}

function BigImageContainer(){
}
BigImageContainer.show = function(caller, url, text){
	var imageheight = $(caller).attr('imageheight');
	
	if(imageheight){
		if(imageheight == 'auto'){
			imageheight = 'auto';
		}else{
			imageheight = parseInt(imageheight)+'px';
		}
		var imagestyle = ' style="height: '+imageheight+'"';
	}else{
		imagestyle = '';
	}
	var	layout = '<div class="toolbar"><a href="#" class="closebutton" onclick="BigImageContainer.close(this);"></a></div>';
		layout += '<div class="image" '+imagestyle+'><div><img src="'+url+'"/></div></div>';
		layout += (text == undefined) ? '' : '<div class="text">"'+text+'"</div>';
	$('#viewerblock .container').html(layout);
	$('#viewerblock').show();
	$('body').css('overflow-y','hidden');
	$('body').scrollTop(0);
	
}
BigImageContainer.close = function(caller){
	$('#viewerblock').hide();
	$('body').css('overflow-y','auto');
}

/*
	where to buy search function
*/
function SearchHandler(CountryCode, CompanyType, CompanyPostcode)
{
	$("#wtb_result").html("loading...");
		$.ajax
		(
			{
				url: "index.php",
				data: "StoryID=38&CountryCode="+CountryCode+"&CompanyType="+CompanyType+"&CompanyPostcode="+CompanyPostcode,
				dataType: "html",
				cache: false,
				success: function(html)
				{
					if(html == ""){
						$("#wtb_result").html("No Result");
					}
					else{
						$("#wtb_result").html(html);
					}
				}
			}
		);
}

