
//to due the conflict with the prototype javascript library
//the noConfilct() function overwrites the "$" alias to jQuery
//also assigning the method to a reference variable is possible
//e.g. var $j = jQuery.noConflict();
jQuery.noConflict();



function slideSwitch() {
  var $active = jQuery('#slideshow DIV.active');

  if ( $active.length == 0 ) $active = jQuery('#slideshow DIV:last');

  // use this to pull the divs in the order they appear in the markup
  var $next =  $active.next().length ? $active.next()
      : jQuery('#slideshow DIV:first');

  // uncomment below to pull the divs randomly
  // var $sibs  = $active.siblings();
  // var rndNum = Math.floor(Math.random() * $sibs.length );
  // var $next  = jQuery( $sibs[ rndNum ] );


  $active.addClass('last-active');

  $next.css({opacity: 0.0})
      .addClass('active')
      .animate({opacity: 1.0}, 1500, function() {
          $active.removeClass('active last-active');
      });
}


//sets the new page and submits the form
function showPage(pageNumber) {
	var pageNumberField = document.getElementById('pagenumber');
	if (pageNumberField != null) {
		pageNumberField.value = pageNumber;
	}
	document.forms.pageForm.submit();
}

//sets the new page and submits the form
function search() {
	//reseting the page number to 0
	var pageNumberField = document.getElementById('pagenumber');
	if (pageNumberField != null) {
		pageNumberField.value = 1;
	}
	//reseting the brands widget (show only favourites)
	var allBrandsField = document.getElementById('allbrands');
	if (allBrandsField != null) {
		allBrandsField.value = 0;
	}
	//setting the search page as action target
	document.forms.pageForm.action = "seidl-search.html";
	document.forms.pageForm.submit();
}


//sets the flag to show all brands and submits the form
function allBrands() {
	var allBrandsField = document.getElementById('allbrands');
	if (allBrandsField != null) {
		allBrandsField.value = 1;
	}
	document.forms.pageForm.submit();
}


//use it for developing
function encodeMT(s) {
	var n = 0;
	var r = "";	
	for( var i=0; i < s.length; i++ ) {
		n = s.charCodeAt( i );
		if( n >= 8364 ) {
			n = 128;
		}
		r += String.fromCharCode(n+8);
	}
	alert(r);
}


function decodeMT(s) {
	var n = 0;
	var r = "";
	for( var i = 0; i < s.length; i++) {
		n = s.charCodeAt( i );
		if( n >= 8364 ) {
			n = 128;
		}
		r += String.fromCharCode(n-8);
	}
	return r;
}

function mt(s) {
	location.href= "mailto:"+decodeMT(s);
}

//checking the content element height and resize it if necessary
function updateContentHeight() {
	// :: info bar ::
	var infoBarElem = jQuery('#info_sidebar');
	var infoBarHeight = 0;
	if (infoBarElem.length != 0) {
		infoBarHeight = infoBarElem.height();
	}
	
	// :: widget bar ::
	var widgetBarElem = jQuery('#widget_sidebar');
	var widgetBarHeight = 0;
	if (widgetBarElem.length != 0) {
		widgetBarHeight = widgetBarElem.height();
	}
			
	// :: text content area ::
	var txtContElem = jQuery('#text_content');
	var txtContHeight = 0;
	if (txtContElem.length != 0) {
		txtContHeight = txtContElem.height();
		//alert("infobar: "+infoBarHeight+", textcontent: "+txtContHeight+", widgetbar: "+widgetBarHeight);
		//check heights
		var newHeight = txtContHeight;
		//infobar
		if (infoBarHeight > newHeight) {
			newHeight = infoBarHeight;
		}
		//widgetbar
		if (widgetBarHeight > newHeight) {
			newHeight = widgetBarHeight;
		}
		//if the new height has been changed -> resize the element
		if (newHeight > txtContHeight) {
			//alert('resize');
			txtContElem.height(newHeight);
		}
	}
}
