﻿/*
* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*
* Uses the built In easIng capabilities added In jQuery 1.1
* to offer multiple easIng options
*
* Copyright (c) 2007 George Smith
* Licensed under the MIT License:
*   http://www.opensource.org/licenses/mit-license.php
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend(jQuery.easing,
{
    def: 'easeOutQuad',
    swing: function (x, t, b, c, d) {
        //alert(jQuery.easing.default);
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeInQuad: function (x, t, b, c, d) {
        return c * (t /= d) * t + b;
    },
    easeOutQuad: function (x, t, b, c, d) {
        return -c * (t /= d) * (t - 2) + b;
    },
    easeInOutQuad: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t + b;
        return -c / 2 * ((--t) * (t - 2) - 1) + b;
    },
    easeInCubic: function (x, t, b, c, d) {
        return c * (t /= d) * t * t + b;
    },
    easeOutCubic: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t + 1) + b;
    },
    easeInOutCubic: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t + 2) + b;
    },
    easeInQuart: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t + b;
    },
    easeOutQuart: function (x, t, b, c, d) {
        return -c * ((t = t / d - 1) * t * t * t - 1) + b;
    },
    easeInOutQuart: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
        return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
    },
    easeInQuint: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t * t + b;
    },
    easeOutQuint: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
    },
    easeInOutQuint: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
    },
    easeInSine: function (x, t, b, c, d) {
        return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
    },
    easeOutSine: function (x, t, b, c, d) {
        return c * Math.sin(t / d * (Math.PI / 2)) + b;
    },
    easeInOutSine: function (x, t, b, c, d) {
        return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
    },
    easeInExpo: function (x, t, b, c, d) {
        return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
    },
    easeInOutExpo: function (x, t, b, c, d) {
        if (t == 0) return b;
        if (t == d) return b + c;
        if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
        return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
    },
    easeInCirc: function (x, t, b, c, d) {
        return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
    },
    easeOutCirc: function (x, t, b, c, d) {
        return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
    },
    easeInOutCirc: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
        return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
    },
    easeInElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
    },
    easeOutElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
    },
    easeInOutElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5);
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
        return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
    },
    easeInBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * (t /= d) * t * ((s + 1) * t - s) + b;
    },
    easeOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
    },
    easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
        return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
    },
    easeInBounce: function (x, t, b, c, d) {
        return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b;
    },
    easeOutBounce: function (x, t, b, c, d) {
        if ((t /= d) < (1 / 2.75)) {
            return c * (7.5625 * t * t) + b;
        } else if (t < (2 / 2.75)) {
            return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
        } else if (t < (2.5 / 2.75)) {
            return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
        } else {
            return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
        }
    },
    easeInOutBounce: function (x, t, b, c, d) {
        if (t < d / 2) return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b;
        return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b;
    }
});


(function ($) {
    jQuery.fn.lavaLamp = function (o) {
        o = $.extend({
            'target': 'li',
            'container': '',
            'fx': 'swing',
            'speed': 500,
            'click': function () {  },
            'startItem': '',
            'includeMargins': false,
            'autoReturn': true,
            'returnDelay': 0,
            'setOnClick': true,
            'homeTop': 0,
            'homeLeft': 0,
            'homeWidth': 0,
            'homeHeight': '30px',
            'returnHome': false,
            'autoResize': false
        },
			o || {});

        // parseInt for easy mathing
        function getInt(arg) {
            var myint = parseInt(arg);
            return (isNaN(myint) ? 0 : myint);
        }

        if (o.container == '')
            o.container = o.target;

        if (o.autoResize)
            $(window).resize(function () {
                $(o.target + '.selectedLava').trigger('mouseenter');
            });
        
        return this.each(function () {
            // ensures parent UL or OL element has some positioning
            if ($(this).css('position') == 'static')
                $(this).css('position', 'relative');

            // create homeLava element if origin dimensions set
            if (o.homeTop || o.homeLeft) {
                var $home = $('<' + o.container + ' class="homeLava"></' + o.container + '>').css({ 'left': o.homeLeft, 'top': o.homeTop, 'width': o.homeWidth, 'height': o.homeHeight, 'position': 'absolute', 'display': 'block' });
                $(this).prepend($home);
            }

            var path = location.pathname + location.search + location.hash, $selected, $back, $lt = $(o.target + '[class!=noLava]', this), delayTimer, bx = 0, by = 0, mh = 0, mw = 0, ml = 0, mt = 0;

            // start $selected default with CSS class 'selectedLava'
            $selected = $(o.target + '.selectedLava', this);

            // override $selected if startItem is set
            if (o.startItem != '')
                $selected = $lt.eq(o.startItem);

            // default to $home element
            if ((o.homeTop || o.homeLeft) && $selected.length < 1)
                $selected = $home;

            // loop through all the target element a href tags and
            // the longest href to match the location path is deemed the most 
            // accurate and selected as default
            if ($selected.length < 1) {
                var pathmatch_len = 0, $pathel;

                $lt.each(function () {
                    var thishref = $('a:first', this).attr('href');
                    //console.log(thishref+' size:'+thishref.length);
                    if (path.indexOf(thishref) > -1 && thishref.length > pathmatch_len) {
                        $pathel = $(this);
                        pathmatch_len = thishref.length;
                    }

                });
                if (pathmatch_len > 0) {
                    //console.log('found match:'+$('a:first',$pathel).attr('href'));
                    $selected = $pathel;
                }
                //else 
                //console.log('no match!');
            }

            // if still no matches, default to the first element
            if ($selected.length < 1) {
                $selected = $lt.eq(0);
            }
               

            // make sure we only have one element as $selected and apply selectedLava class
            $selected = $($selected.eq(0).addClass('selectedLava'));

            // add mouseover event for every sub element
            $lt.bind('mouseenter', function () {
                //console.log('mouseenter');
                // help backLava behave if returnDelay is set
                if (delayTimer) { clearTimeout(delayTimer); delayTimer = null; }
                move($(this));
            }).click(function (e) {
                if (o.setOnClick) {
                    $selected.removeClass('selectedLava');
                    $selected = $(this).addClass('selectedLava');
                }
                return o.click.apply(this, [e, this]);
            });

            // creates and adds to the container a backLava element with absolute positioning
            $back = $('<' + o.container + ' id="backLava"><div class="leftLava"></div><div class="bottomLava"></div><div class="cornerLava"></div></' + o.container + '>').css({ 'position': 'absolute', 'display': 'block', 'margin': 0, 'padding': 0 }).prependTo(this);

            // setting css height and width actually sets the innerHeight and innerWidth, so
            // compute border and padding differences on styled backLava element to fit them in also.
            if (o.includeMargins) {
                mh = getInt($selected.css('marginTop')) + getInt($selected.css('marginBottom'));
                mw = getInt($selected.css('marginLeft')) + getInt($selected.css('marginRight'));
            }
            bx = getInt($back.css('borderLeftWidth')) + getInt($back.css('borderRightWidth')) + getInt($back.css('paddingLeft')) + getInt($back.css('paddingRight')) - mw;
            //by = getInt($back.css('borderTopWidth')) + getInt($back.css('borderBottomWidth')) + getInt($back.css('paddingTop')) + getInt($back.css('paddingBottom')) - mh;

            // set the starting position for the lavalamp hover element: .back
            if (o.homeTop || o.homeLeft) {
                $back.css({ 'left': o.homeLeft, 'top': o.homeTop, 'width': o.homeWidth, 'height': o.homeHeight });
                $back.hide();
            } else {
                if (!o.includeMargins) {
                    ml = (getInt($selected.css('marginLeft')));
                    mt = (getInt($selected.css('marginTop')));
                }
                $back.css({ 'left': $selected.position().left + ml, 'top': $selected.position().top + mt, 'width': $selected.outerWidth() - bx, 'height': o.homeHeight });
            }

            // after we leave the container element, move back to default/last clicked element
            $(this).bind('mouseleave', function () {
                //console.log('mouseleave');
                var $returnEl = null;
                if (o.returnHome)
                    $returnEl = $home;
                else if (!o.autoReturn)
                    return true;

                if (o.returnDelay) {
                    if (delayTimer) clearTimeout(delayTimer);
                    delayTimer = setTimeout(function () { move($returnEl); }, o.returnDelay);
                }
                else {
                    move($returnEl);
                }
                return true;
            });

            function move($el) {
                if (!$el) $el = $selected;
                //$el.addClass("selectedLava");
                $selected.find('a').removeClass('active').css({'height': '24px', 'display':'block'});
                if (!o.includeMargins) {
                    ml = (getInt($el.css('marginLeft')));
                    mt = (getInt($el.css('marginTop')));
                }
                var dims = {
                    'left': $el.position().left + ml,
                    'top': $el.position().top + mt,
                    'width': $el.outerWidth() - bx,
                    'height': o.homeHeight
                };
              
                $back.stop().animate(dims, o.speed, o.fx);
                if(($el.position().left + ml)==0) {
                    $back.hide();
                     $el.removeClass("selectedLava");
                } else {
                    $back.show();
                   
                }
            };
        });

    };
})(jQuery);


function ShowHide(checked, id) {
	var name = "#" + id;
	if (checked) {	    
		$(name).show('slow');
	}
    else 
    {
        if (id == 'inputS3') {
            $("#inputS3 input").val('');
            $("#inputS3 select").val('');
        }
        $(name).hide('slow'); }
    }

function FillValue(value, field1, field2, field3) {
    document.getElementById(field1).value = value;
    if (field2 != null) {
        document.getElementById(field2).value = value;
    }
 if (field3 != null) {
     document.getElementById(field3).value = value;
 }
}



function BillingTypeChange(value,s) {
    if (value == 1) {
        $("#VT").removeClass('required').val('0').attr('min', '');
        $("#MT").removeClass('required').val('0').attr('min', '');

	    if(s) {
	        $("#ET_").addClass('required');
	    }else {
	        $("#ET_").addClass('required').val('').attr('min', '0');
    }
		
		$("#VTMT").hide();
		$("#ET").show();
	}
	else {
	    if(s) {
		    $("#VT").addClass('required');
		    $("#MT").addClass('required');
	    }else {
		    $("#VT").addClass('required').val('').attr('min', '0');
		    $("#MT").addClass('required').val('').attr('min', '0');
	    }
		$("#ET_").removeClass('required').val('0').attr('min', '');
		$("#VTMT").show();
		$("#ET").hide();
	}
}
$(function () {
	$(".trr").keyup(function () {
		if ($(this).val().length == $(this).attr("maxlength")) {
			$(this).next().focus();
		}
	});
});

$(document).ready(function () {
    $('form').submit(function () { $('input[type=submit]', this).attr('disabled', 'disabled'); });

    $('area').each(function () {
        $(this).qtip(
      {
          content: $(this).attr('rel'),
          style: {
              title: { 'font-size': 11, 'font-famly': 'verdana' },
              name: 'green',
              background: '#0096AA',
              color: 'white',
              border: {
                  width: 0,
                  radius: 4,
                  color: '#027787'
              },
              tip: true
          }
      });
    });

   
   
   $("menu").lavaLamp({
        speed: 200,
        homeLeft: '0'
    });

    var href = window.location.href.slice(window.location.href).split('/');
    var link = '';
    for (var i = 3; i < href.length; i++) {
        link = link + '/' + href[i];
    }
    $(".sideMenu a").each(function () {
        if ($(this).attr('href') == link) {
            $(this).parent().addClass('current');
            $(this).parent().parent().parent().addClass('dropped');
        }
    });

    var menu1 = $("menu li.active a.active");
    if (menu1.html() != null) {

        var menu2 = $(".sideMenu ul li.dropped a");
        var menu3 = $(".sideMenu ul li.current a");
        var menu_active = "";
        if ((menu2.html() == null) && (menu3.html() == null)) {
            menu_active = 'class="active"';
        }

        var h_link = $("#odj_active").attr('href');

        $("#breadCrumb").append('<a href="' + h_link + '">domov</a> » ');
        $("#breadCrumb").append('<a ' + menu_active + ' href="' + menu1.attr('href') + '">' + menu1.html().toLowerCase() + '</a> ');
        if (menu2.html() != null) {
            $("#breadCrumb").append(' » <a href="' + menu2.attr('href') + '">' + menu2.html().toLowerCase() + '</a> » ');
            $("#breadCrumb").append('<a class="active" href="' + menu3.attr('href') + '">' + menu3.html().toLowerCase() + '</a>  ');
        } else {
            if (menu3.html() != null) {
                $("#breadCrumb").append(' » <a class="active" href="' + menu3.attr('href') + '">' + menu3.html().toLowerCase() + '</a>  ');
            }
        }
    }

    ($(".sideMenu").has('ul').lenght ? $(".sideMenu").hide() : '');

    jQuery.validator.addMethod("defaultInvalid", function (value, element) {
        return value != element.defaultValue;
    }, "");

    jQuery.validator.addMethod("password", function (value, element) {
        var result = this.optional(element) || value.length >= 6 && /\d/.test(value) && /[a-z]/i.test(value);
        if (!result) {
            element.value = "";
            var validator = this;
            setTimeout(function () {
                validator.blockFocusCleanup = true;
                element.focus();
                validator.blockFocusCleanup = false;
            }, 1);
        }
        return result;
    }, "Your password must be at least 6 characters long and contain at least one number and one character.");

    jQuery.validator.addMethod("billingRequired", function (value, element) {
        if ($("#bill_to_co").is(":checked"))
            return $(element).parents(".subTable").length;
        return !this.optional(element);
    }, "");

    jQuery.validator.addMethod("numberSI", function (value, element) {
        return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
    }, "");

    jQuery.validator.messages.required = "";
    $("form").validate({
        invalidHandler: function (e, validator) {
            var errors = validator.numberOfInvalids();
            if (errors) {
                var message = errors == 1
					? 'Izpustili ste eno polje'
					: 'Število napak: ' + errors;
                $("div.error").html(message);
                $("div.error").show();
            } else {
                $("div.error").hide();
            }
        },
        onkeyup: false,
        submitHandler: function (form) {
            form.submit();

        },
        messages: {
            password2: {
                required: " ",
                equalTo: "Please enter the same password as above"
            },
            email: {
                required: " ",
                email: "Please enter a valid email address, example: you@yourdomain.com",
                remote: jQuery.validator.format("{0} is already taken, please enter a different address.")
            }
        },
        debug: true
    });

    $(".resize").vjustify();
    $("div.buttonSubmit").hoverClass("buttonSubmitHover");

    if ($.browser.safari) {
        $("body").addClass("safari");
    }

    $("input.phone").mask("(999) 999-9999");
    /*$("#TRR1").mask("999");
    $("#TRR2").mask("9999");
    $("#TRR3").mask("9999");
    $("#TRR4").mask("9999");
    */
    $("input.UnitNumber").mask("999999");
    $("input.ddv").mask("99999999");
    var creditcard = $("#creditcard").mask("9999 9999 9999 9999");

    $("#cc_type").change(
	function () {
	    switch ($(this).val()) {
	        case 'amex':
	            creditcard.unmask().mask("9999 999999 99999");
	            break;
	        default:
	            creditcard.unmask().mask("9999 9999 9999 9999");
	            break;
	    }
	}
  );

    // toggle optional billing address
    var subTableDiv = $("div.subTableDiv");
    var toggleCheck = $("input.toggleCheck");
    toggleCheck.is(":checked")
	? subTableDiv.hide()
	: subTableDiv.show();
    $("input.toggleCheck").click(function () {
        if (this.checked == true) {
            subTableDiv.slideUp("medium");
            $("form").valid();
        } else {
            subTableDiv.slideDown("medium");
        }
    });

    if ($('#slides ul').length) {
        $('#slides ul').cycle({
            speed: 200,
            timeout: 7000,
            pager: '#nav',
            pagerEvent: 'mouseover',
            fx: 'fade',
            pauseOnPagerHover: true
        });
        $('#slides ul').hover(
			function () {
			    $('#slides ul').cycle('pause');
			},
			function () {
			    $('#slides ul').cycle('resume');
			}
		);
    }


    $("menu li:nth-child(" + ($("menu li").length - 1) + ")").css('background', 'none');
    $(".summary ul li:last div").css('border', 'none');
    $(".announcement ul li:last div").css('border', 'none');

    $("#eur").focus(function () {
        $(this).val('');
    });

    $('#ConsumptionType').change(function () {
        if ($('#ConsumptionType').val() == '2') {
            $("#vrsta_odjema").show();
            $("#toHide").hide();
            $("#toHide2").hide();
        } else {
            $("#vrsta_odjema").hide();
            $("#toHide").show();
        }
    });

    var params = [];
    $.each($.browser, function (k, v) {
        var pat = /^[a-z].*/i;
        if (pat.test(k)) { params.push(k); }
    });
    params = params.join(' ');
    $('html').addClass(params);


    BillingTypeChange($("#BillingType").val(), true);

    $('#ZavezanecDDV').css("background", "none");
    $('#ZavezanecDDV').css("width", "15");

    $("#tiskanje").click(function () {
        window.print();
    });

    $("#SODO").change(function () {
        var c0 = $("#SODO option:selected").text();
        $("#sodoId").val($(this).val());
        $("#CurrentProvider option").each(function () {
            if (c0 == $(this).text()) {
                $(this).attr("selected", "selected");
            }
        });
    });

});
    
$.fn.vjustify = function () {
	var maxHeight = 0;
	$(".resize").css("height", "auto");
	this.each(function () {
		if (this.offsetHeight > maxHeight) {
			maxHeight = this.offsetHeight;
		}
	});
	this.each(function () {
		$(this).height(maxHeight);
		if (this.offsetHeight > maxHeight) {
			$(this).height((maxHeight - (this.offsetHeight - maxHeight)));
		}
	});
};

$.fn.hoverClass = function (classname) {
	return this.hover(function () {
		$(this).addClass(classname);
	}, function () {
		$(this).removeClass(classname);
	});
};




