// Funktion für das SuckerfishMenu im IE6
startList = function() {
if ( $("#navi").length > 0 ) {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("navi");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
}
window.onload=startList;

// Set watermarks
$(function() {
    $('#search_input').watermark('Suchbegriff');
    $('#newsletter_input').watermark('Gültige E-Mail-Adresse eingeben');
    $('#code_input').watermark('Gutscheincode eingeben');
    $('#search').watermark('E-Mail-Adresse / Name eingeben');
});

// Erstellung des Bestseller-Karrussels
function mycarousel_itemVisibleInCallback_1(carousel, item, i, state, evt) {
    var idx = carousel.index(i, mycarousel_itemList_1.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList_1[idx - 1]));
};

// Erstellung des Angebot-Karrussels
function mycarousel_itemVisibleInCallback_2(carousel, item, i, state, evt) {
    var idx = carousel.index(i, mycarousel_itemList_2.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList_2[idx - 1]));
};

// Erstellung des Zubehör-Karrussels
function mycarousel_itemVisibleInCallback_3(carousel, item, i, state, evt) {
    var idx = carousel.index(i, mycarousel_itemList_3.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList_3[idx - 1]));
};

// Erstellung des Kauften-auch-Karrussels
function mycarousel_itemVisibleInCallback_4(carousel, item, i, state, evt) {
    var idx = carousel.index(i, mycarousel_itemList_4.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList_4[idx - 1]));
};

// Erstellung des Ähnliche-Karrussels
function mycarousel_itemVisibleInCallback_5(carousel, item, i, state, evt) {
    var idx = carousel.index(i, mycarousel_itemList_5.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList_5[idx - 1]));
};

// Erstellung des Passende-Karrussels
function mycarousel_itemVisibleInCallback_6(carousel, item, i, state, evt) {
    var idx = carousel.index(i, mycarousel_itemList_6.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList_6[idx - 1]));
};

// Entfernen eines Karusses
function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
};

// HTML-Code des verwendeten Karussells
function mycarousel_getItemHTML(item) {
    var icon = '';
    if (item.items=='6') icon = 'very_';

    var content = '<div>';
    if (item.sale=='true')
        content += '<div class="sale_advice"><img src="/out/basic/img/layout/sale_'+icon+'small.png" alt="Sale" title="Sale" /></div>';
        content += '<div class="sale_product"><a href="'+item.url+'" title="'+item.title+'"><img src="'+item.img+'" alt="'+item.title+'" title="'+item.title+'" /></a></div>';
        content += '<div>'+item.descr+'</div></div>';
  return content;
};

// Blende Bereiche ein/aus abhängig von Auswahl
function showAdditionalContent() {
    // Zeige Bereich Firmenkunde
    if ($("input[name='company_input']:checked").val() == 'ja') {
        $('.company_hide').show();
    } else {
        $('.company_hide').hide();
        $("input[name='invadr[oxuser__oxcompany]']").val('');
        $("input[name='invadr[oxuser__oxustid]']").val('');
    };

    // Zeige Bereich zusätzliche Mitteilung
    if ($("input[name='add_input']:checked").val() == 'ja') {
        $('.add_hide').show();
    } else {
        $('.add_hide').hide();
    };

    // Zeige Bereiche ausgewählte Zahlungsart
    if ($("input[name='paymentid']:checked").val() == 'mossaferpay') {
        $('.credit_hide').show();
        $('.account_hide').hide();
    } else if ($("input[name='paymentid']:checked").val() == 'oxiddebitnote') {
        $('.credit_hide').hide();
        $('.account_hide').show();
    } else {
        $('.credit_hide').hide();
        $('.account_hide').hide();
    };
    // Zeige Eingabefeld für Kreditkarten CVC auf Zahlungstemplate
    var selectedUserPayment = $("select[name='dynvalue[spMOSUserPaymentId]']").val();
    if(selectedUserPayment == -1 || selectedUserPayment == 0) {
    	$(".cvc_hide").hide();
    } else {
    	$(".cvc_hide").show();
    };

    // Zeige Bereich alle Rechnungsdetails
    if ($("input[name='view_info']:checked").val() == 'ja') {
        $('.details_hide').show();
        $('.nodetails_hide').hide();
    } else {
        $('.details_hide').hide();
        $('.nodetails_hide').show();
    };
}

function toggleShipAddress(event) {
    // Zeige Bereich andere Lieferanschrift
    if ($("input[name='other_input']:checked").val() == 'ja') {
    	$('#userFormHiddenFields').append($('<input type="hidden" name="blshowshipaddress" value="1">'));
    } else {
    	$('#userFormHiddenFields').append($('<input type="hidden" name="blhideshipaddress" value="1">'));
    };

    $('#new_adress').submit();
}

function selectDifferenShipAddress(event) {
	var selectedValue = $(event.target).val();

	$('#reloadaddress').val(selectedValue == -1 ? 1 : 2);

	if(selectedValue == -1)
	{
		$('[name^="deladr[oxaddress__"]').val('');
	}
	else
	{
		$('input[name=fnc]').val('');
		$('#new_adress').submit();
	}
}

$(document).ready(function() {

	showAdditionalContent();

    // Ändert sich der Inhalt einer select-Box führe die Funktion aus
    $('select').change(function() {
      showAdditionalContent();
    });

    // Ändert sich der Inhalt eines input-Feldes führe die Funktion aus
    $('input').change(function() {
      showAdditionalContent();
    });

    // Ändert sich die Auswahl ob Lieferanschrift ja oder nein
    $("input[name='other_input']").change(function(event) {
    	toggleShipAddress(event);
    });

    // Ändert sich die Auswahl der bereits gespeicherten Lieferadressen
    $("select[name='oxaddressid']").change(function(event) {
    	selectDifferenShipAddress(event);
    });
    // Verwendung des Bestseller-Karussels
    $('#mycarousel_1').jcarousel({
      wrap: 'circular',
      start: 1,
      itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback_1},
      itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });

    // Verwendung des Angebot-Karussels
    $('#mycarousel_2').jcarousel({
      wrap: 'circular',
      start: 1,
      itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback_2},
      itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });

    // Verwendung des Zubehör-Karussels
    $('#mycarousel_3').jcarousel({
      wrap: 'circular',
      start: 1,
      itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback_3},
      itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });

    // Verwendung des Kauften-auch-Karussels
    $('#mycarousel_4').jcarousel({
      wrap: 'circular',
      start: 1,
      itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback_4},
      itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });

    // Verwendung des Ähnliche-Karussels
    $('#mycarousel_5').jcarousel({
      wrap: 'circular',
      start: 1,
      itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback_5},
      itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });

    // Verwendung des Passende-Karussels
    $('#mycarousel_6').jcarousel({
      wrap: 'circular',
      start: 1,
      itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback_6},
      itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });

    $('a[rel=external]').click(function(){
    	window.open($(this).attr('href'));
    	return false;
    });
    
    // Fix IE6 .png-Bug
    // $('body').supersleight({shim: 'image/layout/spacer.gif'});
});
