var Timers = new Array();
Timers["hide"] = false;

function BindPrettyPhoto() {
 	$("a[rel^='prettyPhoto']").unbind();
	$("a[rel^='prettyPhoto']").prettyPhoto();
 }

$(document).ready(function() {

	$("div.mainmenu a").hover(
		function () {
     		$(this.children[0]).attr({src:"./style/default/img/mainmenu_bullet_active.png"});
      	}, function () {
     		$(this.children[0]).attr({src:"./style/default/img/mainmenu_bullet.png"});
		}
 	);

	$("a[rel^='prettyPhoto']").prettyPhoto();
 });

function PriceSum(Price, Amount, Identifier, DecSep, Symbolic) {
	var res = 0.0;
	res = Amount*parseFloat("0"+Price, 10);
	res = res.toFixed(2);
	res = res.toString();
	res = res.replace(".",DecSep);
	res = res.replace(",",DecSep);
	if (res.indexOf(DecSep) == 0)
 		res += DecSep+'00';
	else if (res.indexOf(DecSep) == res.length -2)
 		res += '0';
	res += '&nbsp;';
    if(Symbolic == true) {
        res += '&euro;';
    } else {
        res += 'EUR';
    }
	document.getElementById(Identifier).innerHTML = res;
}

function SwapImage_Prepare(Values) {
    if(!Values) return false;
    var Parameters = Values.split(";");
    GetOrderSizeTable(Parameters[3], Parameters[4], Parameters[5]);
    return SwapImage(Parameters[0], Parameters[1], Parameters[2], Parameters[3]);
}

function SwapImage(ImgID, NewImage, Link, VariantID) {
	var NewHTML = "";
    if(Link != false && Link != "false") {
        NewHTML+= '<a href="./images/articles/'+NewImage+'" rel="prettyPhoto"><img src="'+NewImage+'.ath,120,120,bq" alt="'+ImgID+'" height="120" width="120" /></a>';
    } else {
        NewHTML+= '<img src="'+NewImage+'.ith,120,120,bq" alt="'+ImgID+'" height="120" width="120" />';
    }

    $('#aimg_'+ImgID).html(NewHTML);
    $('#artno_'+ImgID).html(VariantID);
    BindPrettyPhoto();
}

function DS_S2(Value) {
    if(Value != -1) {
        $("#dss2").slideDown(250);
        if($("#dss2 input").val().length >= 3) {
            $("#dss3").slideDown(250);
        }

        $("#dss2 span").html(Value+"-");
    } else {
        $("#dss3").slideUp(100);
        $("#dss2").slideUp(100);
    }
}

function DS_S3(Value) {
    if(Value.length >= 3) {
        $("#dss3").slideDown(250);
    } else {
        $("#dss3").slideUp(100);
    }
}

function Prsugcal(Price, SugPriceSrc, CurPriceTar, SugPriceTar, DecSep) {
    var Amount = 0;
    $("fieldset input").each(function() {
        if(parseInt(this.value))
            Amount = Amount + parseInt(this.value);
    });

    PriceSum(Price, Amount, CurPriceTar, DecSep);
    PriceSum(document.getElementById(SugPriceSrc).value, Amount, SugPriceTar, DecSep);
}

function ShowHideToggle(HID) {
    $("tr.hid"+HID).toggle();
}

function TryConfirm(Msg, URL) {
    var Reaction = confirm(Msg);
    if(Reaction) document.location.href = URL;
}

function ShowDropDown(MenuID) {
    $("#ddm_"+MenuID).slideDown(250);
    if(Timers["hide"] != false) {
        clearTimeout(Timers["hide"]);
    }

    Timers["hide"] = setTimeout("HideDropDown('"+MenuID+"')", 3000);
}

function HideDropDown(MenuID) {
    $("#ddm_"+MenuID).slideUp(250);
    Timers["hide"] = false;
}