// Hauptmenu
$jq(document).ready(function () {
	$jq("#mainnav > li").hover(
		function () {
			$jq(this).css("background-position", "0 -21px");
			$jq(this).find("ul").show();
		}, 
		function () {
			$jq(this).css("background-position", "0 0");
			$jq(this).find("ul").hide();
		}
	);
});


// onLoad-functions
$jq(document).ready(function() {

	// init some effects
	Effects();
	LieferVorschlag();

	triggerCopyright();
	
	
});


function Effects() {	
	// hide CustomerData table on Basket
	$jq("#customerData").hide();
	$jq("#differentDeliveryAddress").hide();
	$jq("#deliveryInformation").hide();
	
	// init product list article data
	if ( $jq("#initPList").length ) {
		hideAllArticleDate();
		triggerOpenList();
	}
	
	// init and trigger directOrderForm
	if ( $jq("#directOrderCheck").length ) {
		triggerDirectOrderForm();
	}
	
}

function hideAllArticleDate() {	
	// hide only if id is not available
	if ( !$jq("#showAllInformation").length ) {
		$jq(".pArticle").hide();
	} else {
		$jq(".openArticleList").html($jq("#closeArticleText").html());
	}
}

function triggerOpenList() {
	$jq(".openArticleList").click(
		function() {
			$jq("#pArticle" + this.id ).toggle();
			if ($jq("#pArticle" + this.id).is(':visible')) {
				$jq(this).html($jq("#closeArticleText").html());
			} else {
				$jq(this).html($jq("#openArticleText").html());
			}

		}			
	);
}

//--- directorderForm
//trigger form of directorder
function triggerDirectOrderForm() {
	$jq(".dT").each(function () {
		checkForCurrentArticle( this.value, this.id );
	});
	$jq(".dT").blur(function() {
		if ( this.value != "" ) {
			$jq("#result" + this.id  ).load(directOrderCheckUrl, { 'artnr': this.value } );
		} else {
			$jq( "#result" + this.id ).html("");
		}
	});
} // END function




function checkForCurrentArticle( valueToCheck, ID ) {

	params 	= "artnr=" + valueToCheck;

    jQuery.ajax({
    	type: "GET",
    	 url: directOrderCheckUrl,
    	data: "artnr=" + valueToCheck,
     success: function(data) {
    			$jq( "#result" + ID ).html(data)
    		  }
     });
}
/*	
	new Ajax.Request(directOrderCheckUrl, {
		asynchronous:true,
		onComplete: function(request){ updateDirectOrderFormByID(ID, request)},
		parameters:params})			
}
//show error text or article-description
function updateDirectOrderFormByID( ID, request ) {
	$( "result" + ID ).innerHTML = request.responseText;
}
*/



var nextElement = false;

function setNextElement( elem ) {
	nextElement = elem;
}

function submitDirectOrderForm() {
	if ( nextElement ) {
   	if (nextElement == '*submit*') {
      	return true;
    	} else {
      	eval ('document.directorder.' + nextElement + '.focus();');
      	return false;
      }
	} else {
		return true;
  	}	
}
// --- END directorderForm


/*
$jq(document).ready(function() {
    $jq(".cr").bind("contextmenu", function(e) {
    	alert("Nein");
        e.preventDefault();
    });
}); 



// CopyRight für Produktbilder
$(document).ready(function(){
	// Capture right click
	$(".cr").rightClick( function(e) {
		alert("Bitte beachten Sie, dass die Bilder\nauf dieser Seite nicht frei verwendet werden dürfen\n\nBitte respektieren Sie die Copyright Rechte der Hersteller bzw. Rechteinhaber");
	});
});


*/

/*
$jq(document).ready(function(){
	// Capture right click
	$jq(".cr").rightClick( function(e) {
		alert("Bitte beachten Sie, dass die Bilder\nauf dieser Seite nicht frei verwendet werden dürfen\n\nBitte respektieren Sie die Copyright Rechte der Hersteller bzw. Rechteinhaber");
	});
});
*/





var cr_image = 0;

function triggerCopyright() {
	if (document.layers) {
		document.captureEvents(Event.MOUSEDOWN);
	}
	document.onmousedown   = mouseClick;
	document.oncontextmenu = mouseClick; 	
	
	$jq('.cr').mouseover(function() {
		cr_image = 1;
	});

	$jq('.cr').mouseout(function() {
		cr_image = 0;
	});
}





function mouseClick (e) {
  if (!e)
    e = window.event;
  if (((e.type && e.type == "contextmenu") || (e.button && e.button == 2) || (e.which && e.which == 3)) && cr_image == 1) {
    alert("Bitte beachten Sie, dass die Bilder\nauf dieser Seite nicht frei verwendet werden dürfen\n\nBitte respektieren Sie die Copyright Rechte der Hersteller bzw. Rechteinhaber");
    return false;
  }
}





function LieferVorschlag() {	
	// hide CustomerDate tabel on Basket
	if ( $jq("#deliveryDataEarlyTourValue").length ) {
		basketHandler.initTour();
	}
}


function effectCustomerDate( action ) {
	if ( action == "show" ) {
		$jq("#customerData").fadeIn("fast");
	} else {
		$jq("#customerData").fadeOut("fast");
	}
}

function effectDifferentDeliveryAddress( action ) {
	if ( action == "show" ) {
		$jq("#differentDeliveryAddress").fadeIn("fast");
	} else {
		$jq("#differentDeliveryAddress").fadeOut("fast");
	}
}

function effectDeliveryInformation( action ) {
	if ( action == "show" ) {
		$jq("#deliveryInformation").fadeIn("fast");
	} else {
		$jq("#deliveryInformation").fadeOut("fast");
	}
}

// submit search form on click on label
function execSearch() {
	document.search.query.form.submit();
}

/* base-function */
function popup( url, optionen, popupName ) {
  	popupName = window.open( url, popupName, optionen );
  	if ( popupName ) {
  		if (popupName.focus) popupName.focus();
  	}
  	return false;
}

/* misc popups */
function defaultPopup( url, name ) {
  popup( url, 'width=550,height=350,toolbar=0,menubar=0,resizable=1,scrollbars=1,status=1,left=200,top=200', name );
  return false;
}

function orderPopup( url, name ) {
  popup( url, 'width=685,height=300,toolbar=0,menubar=0,resizable=1,scrollbars=1,status=1,left=200,top=200', name );
  return false;
}

function zoomPopup( url, name ) {
  popup( url, 'width=545,height=600,toolbar=0,menubar=0,resizable=1,scrollbars=1,status=1,left=200,top=200', name );
  return false;
}

function servicePopup( url, name ) {
  popup( url, 'width=650,height=650,toolbar=0,menubar=0,resizable=1,scrollbars=1,status=1,left=200,top=200', name );
  return false;
}

function sizePopup(url, name, width, height, top, left ) {
  popup(url, 'width='+width+',height='+height+',toolbar=0,menubar=0,resizable=1,scrollbars=1,status=1,left='+left+',top='+top+'', name );
}

function isIE() {
	if ( browser.indexOf("msie") == -1 ) {
		return false;	
	}
	else return true;
}

