

/*
 * default methods for demoshop GUI
 * needs jQuery
 * 
 * @author JG
 */

$(document).ready(
	function(){	

	 	//enable infomodus button if there are functions else hide the button
	 	if(typeof activateInfomodus == 'function' && typeof deactivateInfomodus == 'function'){
			$('img#infoButton').click().toggle(function(){
	 			activateInfomodus();
		 	}, function() {
				 deactivateInfomodus();
		 	});
		}else{
			$('img#infoButton').hide();
		}
	 	
	 	
	 	// let the passive tabs fade by mouseover and out
	 	$('div.passive > a').mouseover( function() { $(this).parent().fadeTo('normal', 1); } );
	 	$('div.passive > a').mouseout( function() { $(this).parent().fadeTo('normal', 0.5); } );
	 	
	 	//enable div:hover in IE
	 	if($.browser.msie){
	 		$('div.product').mouseover( function() { $(this).addClass("product-hover") } );
	 		$('div.product').mouseout( function() { $(this).removeClass("product-hover") } );
	 		
	 		$('div.asnImage').mouseover( function() { $(this).addClass("asnImage-hover") } );
	 		$('div.asnImage').mouseout( function() { $(this).removeClass("asnImage-hover") } );
	 		
	 		// fix selectbox width in ie
	 		$('div.asnGroup select').wrap('<div class="ieExpand"></div>');
	 		$('div.asnGroup select').mousedown( function(){ $(this).addClass('ieExpand'); });
	 		$('div.asnGroup select').blur( function(){ $(this).removeClass('ieExpand'); });
	 	}
		
		//set blur and focus events for the query input
		//$(document.forms["search_word_inc"]["query"]).blur( function() { checkInputText(); } );
		//$(document.forms["search_word_inc"]["query"]).focus( function() { hideDefaultInputText(); } );	
	
		//fade out the deleted products so user sees which articles are in the trash
		if(typeof fadeDeletedProducts == 'function' && typeof fadeDeletedProducts == 'function'){
			fadeDeletedProducts();
		}
		
		$('#search_word_inc').submit(function() {
			var input = document.forms['search_word_inc']['query'];
			if ($.trim(input.value) !== '') {
				return true;
			} else {
				alert('Bitte gib einen Suchbegriff ein.');
				return false; // submit "abbrechen"
			}
		});
		

		$('#ff_search_button').click(function() {
			//alert('ff_submit');
			$('#search_word_inc').submit();
		});
		
	}
);

function activateManagement(){

	//fade out the deleted products so user sees which articles are in the trash
	if(typeof fadeDeletedProducts == 'function' && typeof fadeDeletedProducts == 'function'){
		fadeDeletedProducts();
	}

	//show xml-button
	$('img#xmlButton').show();

	//show trashcan Button
	$('img#trashcanButton').click().toggle(function(){
	 		activateProductTrash();
		}, function() {
			 deactivateProductTrash();
		});
	$('img#trashcanButton').show();
	
	if(typeof activateCustomManagement == 'function'){
		activateCustomManagement();
	}
}

function deactivateManagement(){	
	if(typeof deactivateProductTrash == 'function'){
		deactivateProductTrash();
	}
	$('img#xmlButton').hide();
	
	$('img#trashcanButton').hide();
	
	if(typeof deactivateCustomManagement == 'function'){
		deactivateCustomManagement();
	}
}


function imageNotFound(img){
	//if the product picture wasn't found use a default picture
	$(img).show();
	img.src = 'images/demoshop/noProductPicture.jpg';
	img.onerror = null;
}
function resizePicture(img, maxWidth, maxHeight){
	$(img).show();
	//resize a picture so it fits into the div 
	if(img.width > maxWidth){ img.width = maxWidth; }
	if(img.height > maxHeight){ img.height = maxHeight; }
}


function hideDefaultInputText(){
	var input = document.forms['search_word_inc']['query'];
	//if the default text is in the field remove it and remove css-class
	if($.trim(input.value) == 'Suchbegriff eingeben...'){
		input.value = '';
		$(input).removeClass('default');
	}
}
function checkInputText(){
	var input = document.forms['search_word_inc']['query'];
	if($.trim(input.value) == ''){
		//if there is no query write default text and add css class. 
		input.value = 'Suchbegriff eingeben...';
		$(input).addClass('default');
	}
}

