/*
Copyright:
copyright (c) 2007 Andr? Fiedler, <http://visualdrugs.net>

License:
MIT-style license.
*/
String.extend({	

/*
Property: utf8Encode
	encodes an ISO-8859-1 string to UTF-8.
*/
utf8Encode: function(){
	var c;
	var encoded = '';
	var s = this.replace(/\r\n/g,"\n");
	var i = 0;
	var l = s.length;

	while(i < l){
		c = s.charCodeAt(i);
		if(c < 128) encoded += String.fromCharCode(c);
		else {
			if((c > 127) && (c < 2048)){
				encoded += String.fromCharCode((c >> 6) | 192);
				encoded += String.fromCharCode((c & 63) | 128);
			} else {
				encoded += String.fromCharCode((c >> 12) | 224);
				encoded += String.fromCharCode(((c >> 6) & 63) | 128);
				encoded += String.fromCharCode((c & 63) | 128);
			}
		}
		i++;
	}
	return encoded;
},
 
/*
Property: utf8Decode
	converts a string with ISO-8859-1 characters encoded with UTF-8 to single-byte ISO-8859-1.
*/
utf8Decode: function(){
	var decoded = '';
	var s = this;
	var l = s.length;
	var i = c = c1 = c2 = 0;

	while(i < l){
		c = s.charCodeAt(i);
		if(c < 128){
			decoded += String.fromCharCode(c);
			i++;
		} else {
			if((c > 191) && (c < 224)){
				c2 = s.charCodeAt(i+1);
				decoded += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = s.charCodeAt(i+1);
				c3 = s.charCodeAt(i+2);
				decoded += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
	}
	return decoded;
}
});

function smoothScroll(e) {
	var myEvent = new Event(e);
	var target = (!myEvent.target.href) ? myEvent.target.parentNode : myEvent.target;
	var divToScrollTo = target.href.split('#')[1];
	new Fx.Scroll(window).toElement(divToScrollTo);
	myEvent.stop();
}

function initSmoothScroll() {
	var smooth_links = $$('a.smooth'); 
	$each(smooth_links, function(smooth_link) {smooth_link.addEvent('click', smoothScroll);});
}

function toggleSendForm(e) {
	var myEvent = new Event(e);
	myEvent.stop();
	sendtofriendFormSlider.toggle()
}

function initSendForm() {
	if(!$('sendtofriend')) return;
	$('sendtofriend').display = 'none';
	var buttonSendToFriend = $('btsend');
	var buttonSendToFriend2 = $('btsend2');
	sendtofriendFormSlider= new Fx.Slide('sendtofriend', {duration: 500}); 
	// hide the form
	sendtofriendFormSlider.hide();
	$('sendtofriend').style.display = 'block';
	// add behavior
	buttonSendToFriend.addEvent('click', toggleSendForm)
}


function toggleMoreCompanies(e) {
	var myEvent = new Event(e);
	myEvent.stop();
	moreCompaniesSlider.toggle()
}

function initHerstellerList() {
	if(!$('moreCompanies')) return;
	$('moreCompanies').display = 'none';
	var buttonMoreCompanies = $('moreCompaniesBTN');
	
	moreCompaniesSlider= new Fx.Slide('moreCompanies', {duration: 500}); 
	// hide the form
	moreCompaniesSlider.hide();
	$('moreCompanies').style.display = 'block';
	// add behavior
	buttonMoreCompanies.addEvent('click', toggleMoreCompanies)
}

function initSmoothScroll() {
	var smooth_links = $$('a.smooth'); 
	$each(smooth_links, function(smooth_link) {smooth_link.addEvent('click', smoothScroll);});
}

function CreateBookmark(url, title) 
{
	if (window.sidebar) 
	{ // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} 
	else if( window.external ) 
	{ // IE Favorite
		window.external.AddFavorite( url, title); 
	}
	else if(window.opera && window.print) 
	{ 
		// Opera Hotlist
		return true; 
	}
}

function hideonjs()
{
	$$('div.hideonjs').setStyle('display', 'none');
}

function showonjs()
{
	$$('div.showonjs').setStyle('display', '');
}


var load_method = (window.ie ? 'load' : 'domready'); // ie fix

window.addEvent(load_method, initSendForm);
window.addEvent(load_method, initHerstellerList);
//window.addEvent(load_method, initSmoothScroll);
window.addEvent(load_method, hideonjs);
window.addEvent(load_method, showonjs);

