function addhistory(link) {
	jQuery.cookie('historylink', link, { path: '/' });
}

/*function addhistory(link,page,div,url) {
	jQuery.cookie('historylink', link, { path: '/' });
	jQuery.cookie('historypage', page, { path: '/' });
	jQuery.cookie('historydiv', div, { path: '/' });
	jQuery.cookie('historyurl', url, { path: '/' });
}*/

function callhistory(base) {
	history.back();
}
/*
function callhistory(base) {
	var tgt = jQuery.cookie('historylink');
	//alert(tgt);
	if (tgt!=null) {
		location.href='/cookingstars'+tgt;
		jQuery.cookie('historylink', '', { expires: -1,path: '/' });
	} else {
		history.back();
	}
}*/

function close_feedback_form()
{
	jQuery("#pict_feedback").css("border","0px none");
	jQuery("#feedback_form").slideUp("slow");
}

function close_mail_form()
{
		jQuery("#pict_mail").css("border","0px none");
		jQuery("#mail_form").slideUp("slow");
}

//FIX IE6 FLICKER BUG!

try {

	document.execCommand("BackgroundImageCache", false, true);

} catch(err) {}	

function addLogo() {
	 var so = new SWFObject("/cookingstars/swf/logo_cs_ani2.swf", "swflogoswf", "329","85", "6", "#e4dbb9");
	 so.addParam("wmode", "transparent");
	 so.setAttribute("style", ";");
	 so.write("logoswf");
	 clearInterval(logo);
}

function addRegTeaser() {
	 var so = new SWFObject("/cookingstars/swf/reg_teaser3.swf", "regteaser", "470", "330", "8", "#FFFFFF");
	 so.addParam("wmode", "transparent");
	 so.setAttribute("style", ";");
	 so.write("homeflash");
	 clearInterval(regteaser);
}

function addTVplayer() {
	var so = new SWFObject("/cookingstars/swf/tvplayer.swf", "swfvideo", "308", "342", "9", "#ffffff");
 	so.addParam("wmode", "transparent");
 	so.setAttribute("style", ";");
 	so.write("webtv_cont_tmp");
 	clearInterval(tvplayer);
}

	
function TestLoginInput(){
	var un = jQuery("input[id$='username']").val();
	var pw = jQuery("input[id$='username']").val();
	if(un!='' && pw!='') {
		return true;
	} else {
		//new Effect.Shake(document.getElementById('skaker'));
		return false;
	}
}

function addFadeOutLoading(div) {
	if (jQuery.browser.msie) {
		jQuery('#'+div).find('.modContent').html('<span><img src="/cookingstars/img/loading.gif"></span>');
	} else {
		//new Element.setOpacity(div, 0.9)
		jQuery('#'+div).find('.modContent').html('<span><img src="/cookingstars/img/loading.gif"></span>');
	}
}

function addFadeInLoading(div) {
	/*if (jQuery.browser.msie) {
		//alert(1);
		//jQuery('#'+div).fadeTo("slow", 1);
	} else {
		//new Element.setOpacity(div, 1)
	}*/
}

function PeriodicalRequest(page,div)
{
	document.getElementById(div).innerHTML = '<img src="/cookingstars/img/loading.gif">';
	new Ajax.PeriodicalUpdater(div, page, {
	  method: 'get', frequency: 60, decay: 1, evalScripts:true
	});
}
//, evalScripts:true
function Request(page,div)
{
	//alert(page+" "+div+" "+document.getElementById(div).innerHTML)
   	addLoading(div);
    new Ajax.Updater(div, page, {asynchronous:true, evalScripts:true});
}

function AsyncRequest(page,div)
{
	//alert(page+" "+div+" "+document.getElementById(div).innerHTML)
   	addLoading(div);
    new Ajax.Updater(div, page, {asynchronous:false, evalScripts:true});
}

function smallRequest(page,div)
{
   	addSmallLoading(div);
    new Ajax.Updater(div, page, {asynchronous:true, evalScripts:true});    
}

function flashRequest(page,div)
{
   	addSearchLoading(div);
    new Ajax.Updater(div, page, {asynchronous:true, evalScripts:true});    
}

function navigationRequest(page,div)
{
   	addSmallLoading(div);
    new Ajax.Updater(div, page, {asynchronous:true, evalScripts:true});    
}

function addBaseLoading(div,h,w) {
	try {
		var rand = Math.random()+"";
		document.getElementById(div).innerHTML = '<div id="loading'+rand+'" class="loading"><img src="/cookingstars/img/loading.gif"></div>';
	} catch (e) {
		//alert(div +" "+e);
		//alert(e+ " "+div);
	}
}

function addFlashLoading(div,h,w) {
	try {
	 var rand = Math.random()+"";
	 document.getElementById(div).innerHTML = '<div id="loading'+rand+'" class="loading"><img src="/cookingstars/img/loading.gif"></div>';
	 //document.getElementById(div).innerHTML = '<img src="/cookingstars/img/spinner.gif">'
	 var so = new SWFObject("/cookingstars/swf/loading.swf", "swf"+rand, h, w, "6", "#FF0000");
	 so.addParam("wmode", "transparent");
	 so.setAttribute("style", ";");
	 so.write("loading"+rand);
	} catch (e) {
		alert(div +" "+e);
		//alert(e+ " "+div);
	}
}

function addBGLoading(div) {
	var rand = Math.random()+"";
	document.getElementById(div).innerHTML = '<div id="bgloading'+rand+'" class="loadingbg"><img src="/cookingstars/img/loading.gif"></div>';
	addBaseLoading('bgloading'+rand,40,40);
}


function addLoading(div) {
	addBaseLoading(div,40,40)
}

function addLoginLoading(div) {
	addFlashLoading(div,20,20)
}

function addSearchLoading(div) {
	addFlashLoading(div,10,10)
}

function addSmallLoading(div) {
	addBaseLoading(div,10,10)
}

var DragScrollable = Class.create();
DragScrollable.prototype = {
  initialize: function(element) {
    this.element = $(element);
    this.active = false;
    this.scrolling = false;

    this.element.style.cursor = 'pointer';

    this.eventMouseDown = this.startScroll.bindAsEventListener(this);
    this.eventMouseUp   = this.endScroll.bindAsEventListener(this);
    this.eventMouseMove = this.scroll.bindAsEventListener(this);

    Event.observe(this.element, 'mousedown', this.eventMouseDown);
  },
  destroy: function() {
    Event.stopObserving(this.element, 'mousedown', this.eventMouseDown);
    Event.stopObserving(document, 'mouseup', this.eventMouseUp);
    Event.stopObserving(document, 'mousemove', this.eventMouseMove);
  },
  startScroll: function(event) {

    this.startX = Event.pointerX(event);
    this.startY = Event.pointerY(event);
    if (Event.isLeftClick(event) &&
        (this.startX < this.element.offsetLeft + this.element.clientWidth) &&
        (this.startY < this.element.offsetTop + this.element.clientHeight)) {
      this.element.style.cursor = 'move';
      Event.observe(document, 'mouseup', this.eventMouseUp);
      Event.observe(document, 'mousemove', this.eventMouseMove);
      this.active = true;
      Event.stop(event);
    }
  },
  endScroll: function(event) {
    this.element.style.cursor = 'pointer';
    this.active = false;
    Event.stopObserving(document, 'mouseup', this.eventMouseUp);
    Event.stopObserving(document, 'mousemove', this.eventMouseMove);
    Event.stop(event);
  },
  scroll: function(event) {
    if (this.active) {
      this.element.scrollTop += (this.startY - Event.pointerY(event));
      this.element.scrollLeft += (this.startX - Event.pointerX(event));
      this.startX = Event.pointerX(event);
      this.startY = Event.pointerY(event);
    }
    Event.stop(event);
  }
}

	function changeElements(i)
	{	
		var obj = document.getElementById('TeaserPageId');
		obj.id = "TeaserPageId_" + i;		
		obj.name = "data[Teaser][Pages][" + i + "][page_id]";
		
		obj = document.getElementById('TeaserColorId');
		obj.id = "TeaserColorId_" + i;		
		obj.name = "data[Teaser][Pages][" + i + "][color_id]";
		
		obj = document.getElementById('TeaserOrder');
		obj.id = "TeaserOrder_" + i;
		obj.name = "data[Teaser][Pages][" + i + "][order_num]";
		
		obj = document.getElementById('TeaserLimited');
		obj.id = "TeaserLimited_" + i;
		obj.name = "data[Teaser][Pages][" + i + "][limited]";						
	}
	
	
/* #### headerCheckSize #############################
   Parameter: 	str 	-> text der gekürzt werden soll
   		div 	-> unsichtbares html element(div) in das geschrieben wird,
   		maxsize	-> max. höhe des bereichs
   
   Info: 	das unsichtbare div element muss die gleichen style eigenschaften haben wie der ausgabe-div, 
   		die breite wird fix zugewiesen, die höhe wird nicht definiert
   
   Return:	gekürzter String + " ..."
*/

/*
	var chars = new Array ('&','à','á','â','ã','ä','å','æ','ç','è','é',
	                       'ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô',
	                       'õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À',
	                       'Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
	                       'Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö',
	                       'Ø','Ù','Ú','Û','Ü','Ý','Þ','È','\"','ß','<',
	                       '>','¢','£','¤','¥','¦','§','¨','©','ª','«',
	                       '¬','­','®','¯','°','±','²','³','´','µ','¶',
	                       '·','¸','¹','º','»','¼','½','¾');

	var entities = new Array ('amp','agrave','aacute','acirc','atilde','auml','aring',
	                          'aelig','ccedil','egrave','eacute','ecirc','euml','igrave',
	                          'iacute','icirc','iuml','eth','ntilde','ograve','oacute',
	                          'ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc',
	                          'uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc',
	                          'Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute',
	                          'Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde',
	                          'Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave',
	                          'Uacute','Ucirc','Uuml','Yacute','THORN','euro','quot','szlig',
	                          'lt','gt','cent','pound','curren','yen','brvbar','sect','uml',
	                          'copy','ordf','laquo','not','shy','reg','macr','deg','plusmn',
	                          'sup2','sup3','acute','micro','para','middot','cedil','sup1',
	                          'ordm','raquo','frac14','frac12','frac34');

String.prototype.fromHtmlToString = function() {
	newString = this;
	
	for(var i = 0; i < chars.length; i++) {
		myRegExp = new RegExp();
		myRegExp.compile('&'+entities[i]+';','g')
		newString = newString.replace (myRegExp, chars[i]);
	}
	return newString;
}

// wandelt eine Zeichenkette, die normalen Text enthält, in einen String mit HTML Schreibweise um
String.prototype.fromStringToHtml = function() {
	newString = this;
	
	// <Entity Numbers in Text umwandeln>
		var entity_match = newString.match(/(\&\#){1}([0-9]+)(\;){1}/g);
		
		if(entity_match != null) {
			for(var h = 0; h < entity_match.length; h++) {
				var entity_number = entity_match[h].substring(2, (entity_match[h].length)-1);
				var entity_to_unicode = String.fromCharCode(entity_number);
				var reg = new RegExp(entity_match[h],"g");
				
				newString = newString.replace(reg, entity_to_unicode);
			}
		}
	// </Entity Numbers in Text umwandeln>
	
	var newString = newString.replace(/(\&\#){1}(.+)(\.\.\.){1}/g, " ..."); // für zerstörte Entities, z.B. &#39 => ohne Strichpunkt
	
  	for(var i = 0; i < chars.length; i++) {
		myRegExp = new RegExp();
		myRegExp.compile(chars[i],'g')
		newString = newString.replace (myRegExp, '&' + entities[i] + ';');
	}
	return newString;
}


	function headerCheckSize(str, div, maxsize) {
		var div_size_check = false;
		var i=5; // anzahl der zeichen die vom string entfernt werden
		var str = str.fromHtmlToString();
		while(div_size_check == false) {
			//temp. div auswählen und variable mit string + punkte setzen
			var str_dot = str.substr(0, (str.length-i)) + " ...";
			//in temp. div schreiben, um die höhe ermitteln zu können
			jQuery(div).html(str_dot);
			if(jQuery(div).height() >= maxsize) div_size_check = false;
			else div_size_check = true;
			i++;
		}
		//alert(jQuery(div).width())
		return str_dot.fromStringToHtml();
	}
	*/
// ##################################################