
$(document).ready(function() {

	// stretching dotted lines on the left + right
	var containerHeight = $('#container').outerHeight();
	$('#dots-left').css('height',containerHeight);
	$('#dots-right').css('height',containerHeight);


	// handling initial search form content
	var searchForm = $("#search input.text");
	searchForm.focusin(function() { if( searchForm.attr('value') == searchForm.attr('data-placeholder-value') ) searchForm.attr('value', "");	});
	searchForm.focusout(function() { if( searchForm.attr('value') == '' ) searchForm.attr('value', searchForm.attr('data-placeholder-value')); });


	// language selector
	$('#l10n .selector').hover(function() { 
			$('#l10n .dropdown').slideDown(); 
			$('#l10n .dropdown').hover(null, function() {
				$('#l10n .dropdown').slideUp();
			});
		}
	);


	// country selector
	try
	{
		$('#country').dropDownPanels({
			speed:200,
			resetTimer:400
		});
		$('.country-value').click(function() {
				var e = $(this);
				$.ajax({
						"type":"GET",
						"url":"scrgetaddressdetailsfromscript.json",
						"data":{"cty":e.html(),"ctyid":e.attr("id").toString(),"prdid":e.parent().attr("class").toString()},
						"dataType":"JSON",
						"error": function(jqXHR, textStatus, errorThrown) {
								//alert("Error! "+textStatus);
							},
						"success": function(contact) {
								String.prototype.unescapeUtf8 = function(){ return decodeURIComponent(escape(this)); };
								var i=0;
								var dat, addr;
								if (contact.actionSuccess == "true")
								{
									$("#country-selector").empty().append(unescape(contact.country));

									dat = "<!-- -->";
									for (i=0; i<contact.details.length; i++)
									{
										dat += '<div class="'+((i>0) ? 'address-data-n' : 'address-data-f')+'">'
										dat += '<span class="country-name">'+unescape(contact.details[i].name1+' '+contact.details[i].name2).unescapeUtf8()+'</span><br />'
										dat += '<span class="country-name">'+unescape(contact.details[i].countryname)+'</span><br />';
										dat += unescape(contact.details[i].detail.firstname+' '+contact.details[i].detail.lastname).unescapeUtf8()+'<br />';
										dat += (contact.details[i].detail.phone_direct) ? 'P: '+contact.details[i].detail.phone_direct+'<br />' : '';
										dat += (contact.details[i].detail.fax_direct) ? 'F: ' + contact.details[i].detail.fax_direct+'<br />' : '';
										dat += (contact.details[i].detail.email) ? '<a href="mailto://'+contact.details[i].detail.email+'" class="mail">MAIL</a><br />' : '';
										dat += (contact.details[i].detail.skype_direct) ? '<a href="callto://'+contact.details[i].detail.skype_direct+'" class="mail">SKYPE</a><br />' : '';
										dat += (contact.details[i].skype_main) ? '<a href="callto://'+contact.details[i].skype_main+'" class="mail">SKYPE</a><br />' : '';
										dat += (contact.details[i].detail.remarks_direct) ? '<span class="remarks">'+unescape(contact.details[i].detail.remarks_direct)+'</span><br />' : '';
										// picture
										dat += '</div>';
									}

									addr = $("#address");
									addr.empty().show().addClass("text-with-image");
									// picture
									addr.append('<div>'+dat+'</div><div class="clear-float"></div>');
								}
								else
								{
									$("#country-selector").replaceWith("Select country");
								}
							},
						"cache":false
					}
				);
			}
		);
	}
	catch(e) {  }


	// accordions incl. pre-setting
	var id = parseInt('41894',10);
	var accordionIndex = 0;
	var pageAccordion = $('.accordion');

	try
	{
		if (pageAccordion)
		{
			var aCookie;
			var sCookie = $.cookie('acc' + id.toString());
			var mainAccordion = $('.accordion h1');
			if (sCookie)
			{
				aCookie = sCookie.split("x");
				if (mainAccordion && !accordionIndex)
				{
					accordionIndex = parseInt(aCookie[2],10);
				}
			}
			mainAccordion.click(function() {
				$.cookie('acc' + id.toString(), $(this).attr('id'));
			});

			$.each(pageAccordion, function() {
				$(this).accordion({autoHeight:false, collapsible:true, active:accordionIndex});
			});
		}
	}
	catch(e) {  }


	// hoverable blocks
	$.each($('.hoverable-block'), function() {
		$(this).hover(function() { 
				$(this).children('.hover').show();
				$(this).children('.hover').hover(null, function() {
					$(this).hide();
				});
		},

		function() {
			$(this).children('.hover').hide();
		});
	});


	// having a-tags as block elements with a lot of content can lead to unexpected behaviour, so..
	$.each($('.hover'), function() {
		if( $(this).attr('data-url') )
		{
			$(this).click(function() { document.location = $(this).attr('data-url'); });
		}
	});
	

	// if a tab exists
	if($('#tabs').size() == 1) $('#tabs').tabs();	

});



var HuSu = {

maxWidthSmall:	1185,
maxWidthStd:	1441,

// addy
addy0815: function(s, l)
{
	var c1 = "&";
	var c2 = "#";
	var c3 = ";";
	var a1 = s.replace(/\[/gi, c1+""+c2).replace(/\]/gi, c3);
	var a2 = (l) ? l.replace(/\[/gi, c1+""+c2).replace(/\]/gi, c3) : "";

	document.write(((!l) ? 'em' + 'ai' + 'l:' : '') + '<a ' + 'hr'+'ef'+'="' + ("&#"+"109;")+"a"+("&#"+"105")+"l"+("&#"+"116;")+"o"+':' + a1 + '">' + ((!l) ? a1 : a2) + '<\/a>');

	return void(0);
},

pageQuery: function(q)
{
	this.keyValuePairs = new Array();

	if (q.length > 1)
	{
		this.q = q.substring(1, q.length);
	}
	else
	{
		this.q = null;
	}
	if (q)
	{
		for(var i=0; i<this.q.split("&").length; i++)
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function(){ return this.keyValuePairs; }
	this.getValue = function(s)
	{
		for(var j=0; j<this.keyValuePairs.length; j++)
		{
			if (this.keyValuePairs[j].split("=")[0] == s) return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function()
	{
		var a = new Array(this.getLength());
		for(var j=0; j<this.keyValuePairs.length; j++)
		{
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function(){ return this.keyValuePairs.length; }
}


//=== end of library "HuSu" ===
}
