/**
 * $Id: main_page.js 212 2010-05-25 19:21:01Z manfred $
 * 
 * $Log: main_page.js,v $
 * Revision 1.3  2007/06/25 13:11:53  administrator
 * Param String für Hersteller -Suche darf nicht von der Klasse String sein.
 *
 * Revision 1.2  2007/04/24 05:44:12  administrator
 * Session id in fastviewSearchCriteria() ergänzt
 *
 * Revision 1.1  2007/04/18 05:27:42  administrator
 * Neues JS-File für allle Seiten um die Schnellübersicht zu realisieren
 *
 * 
 * Created 15.04.2007
 * by manfred ursprung email : manfred.ursprung@manfred-ursprung.de
 * 
 * 
**/

$j().ready(function(){
	
	$j("#simpleSearch").autocomplete('ajax_driven.php', {
		extraParams: {action: "simpleSearch"},
		width: 300,
		max: 12,
		multiple: true,
		matchContains: true,
		minChars: 2,
		cacheLength: 0,
		multiple: false,
		multipleSeparator: ''
	});
	/*
	var bottomBoxes = $j(".ap-test");
	if(bottomBoxes.size() > 0){
		positionLeftAndRightBoxes();
	}
	*/
	//change the language for the site
	$j("select.sitelanguage").bind('change', function(){
		//alert("option for language has changed");
		document.forms['languages'].submit();
	});
	//change the currency for the site
	$j("select.siteCurrency").bind('change', function(){
		//alert("option for language has changed");
		document.forms['currencies'].submit();
	});
	
})


	/* Ajax call to get either all manufacturers as a dropdown list or 
	 * all categories in a drop down list
	 * @param String	forWhat either manufacturers or categories
	 * @param String  node4Succes	id of node where the result will be shown
	 */
var fastviewIndicator;		//node for Indicator that system is making a request. Is needed for hideSearchIndicator

var fastviewSearchCriteria = function(forWhat, node4Success, languageCode, sessionId){
	 var pars = "action=fastview&searchCriteria=" + forWhat +"&language=" + languageCode + "&osCsid=" + sessionId;
	 if(forWhat == 'manufacturers'){
	 	fastviewIndicator = 	$('fastviewManufacturerIndicator');
	 }else if(forWhat == 'designer'){
	 	fastviewIndicator = 	$('fastviewDesignerIndicator');
	 }else if(forWhat == 'categories'){
	 	fastviewIndicator = 	$('fastviewCategoriesIndicator');
	 }
	 fastviewIndicator.style.display = "inline";
	 var myAjax = new Ajax.Updater({
			success: node4Success,
			failure: node4Success},
			"ajax_driven.php", 
			{
				method: 'get', 
				parameters: pars, 
				onFailure: showError,
				onComplete: hideSearchIndicator
				//onSuccess: wrapForm
			});
}

var showError = function(response)	{
	alert("Error: " + response.status + "\t" + response.statusText + "\t" + response.responseText);
} 

var hideSearchIndicator = function(response){
	fastviewIndicator.style.display = "none";
}



var manufacturer_selected = function(form){
	//var id = form.fastview_selection_list.options[form.fastview_selection_list.selectedIndex].value;
	//alert("Manufacturers ID: " + id);
	//$('manufacturers_id').value = id;
	form.submit();
}

var category_selected = function(form){
	var id = form.fastview_selection_list.options[form.fastview_selection_list.selectedIndex].value;
	alert("cPath: " + id);
	$('cPath').value = id;
	form.submit();
}

/**
 * on HOME we must cut the bottom on one line. The left and right column and center has different height.
 * To make the height equal we have to put the divs #ap-left and #ap-right at the bottom
 *  
 * @return
 */

var __positionLeftAndRightBoxes = function(){
	var heightLeft = $j(".left").height();
	var heightRight = $j(".right").height()
	if(heightLeft >= heightRight){
		$j('.ap-left').css({
					"margin-top": "60px",
					"margin-bottom": "20px"
			})
	}
	if(heightLeft < heightRight){
		var marginTop = heightRight - heightLeft;
		if(marginTop < 60) marginTop = 60;
		$j('.ap-right').css({
					"margin-top": marginTop,
					"margin-bottom": "20px"
			})
	}
	
}	

var positionLeftAndRightBoxes = function(){
	var cols = $j(".left").add(".center").add(".right");
	var tallest= 0;
	var dontChange;  //index of tallest 
	for (var i=0; i<cols.size(); i++){
		if($j(cols[i]).innerHeight() > tallest){
			tallest = $j(cols[i]).height();
			dontChange = i;
		}
	}
	var boxes = $j(".left .ap-left").add(".center .present-box").add(".right .ap-right")
	if (tallest>0){
		for (var i=0; i<cols.size(); i++){
			if(i != dontChange){
				var diff = tallest - $j(cols[i]).height();
				$j(boxes[i]).css({
							"margin-top": diff
				});
			}
		}
	}
}

