
$(document).ready(function(){
						   
$("a.iframe").fancybox({
				'width'				: '95%',
				'height'			: '95%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});


var option = {
  x:      1, 
  y:      1, 
  radius: 1,
  color:  "#000"
}
var option2 = {
  x:      0.8, 
  y:      0.8, 
  radius: 0.8,
  color:  "#000"
}

$("#menu_horizontal li a").textShadow( option );
$(".bottomHeaders").textShadow( option2 );

//bottom decorator - scroll up
$("#top").click(function(){
   $("html, body").animate({scrollTop:0}, "fast"); 
});


// inputs design
$(function() {
    //find all form with class jqtransform and apply the plugin
    $("form.jqtransform").jqTransform();
});

//images with fading opacity
$(".fading").css("opacity",0);
$(".fading").fadeTo("slow",1);

// Error animation
$(".status").css("opacity",0).fadeTo("slow",1).animate( { borderLeftWidth:"20px", marginBottom:"20px" }, 800);
$("a.cartHeader").css("opacity",0).fadeTo("fast",1);

$("div#menu_vertical ul li a").mouseover(function(){
	$(this).animate( { paddingLeft:"25px" }, 100);
    }).mouseout(function(){
   	$(this).animate( { paddingLeft:"20px" }, 100);
    });

currentelem = $("div#menu_vertical ul li a");
if (currentelem.is ("#submenu_current")) {
	
$("div#menu_vertical ul li a").css("opacity",0).fadeTo("fast",0.7);
$("div#menu_vertical ul li a").mouseover(function(){
	$(this).animate( { opacity:"1" }, 100);
    }).mouseout(function(){
   	$(this).animate( { opacity:"0.7" }, 100);
    });
	
$("div#menu_vertical ul li a#submenu_current").css("opacity",7).fadeTo("fast",1);
$("div#menu_vertical ul li a#submenu_current").mouseover(function(){
	$(this).animate( { opacity:"1" }, 1);
    }).mouseout(function(){
   	$(this).animate( { opacity:"1" }, 500);
    });


}


// Fade images: class="fade"
$(".fade").css("opacity",0.8).mouseover(function(){
	$(this).fadeTo("fast",1);
    }).mouseout(function(){
   	$(this).fadeTo("fast",0.8);
    });

//Fade buttons
$(".button").css("opacity",0.90).mouseover(function(){
	$(this).fadeTo("fast",1);
    }).mouseout(function(){
   	$(this).fadeTo("fast",0.90);
    });

// Catalog ODD, table background-color:
$("div.every-product-wrap:odd").addClass("odd-row-style");

// Catalog ODD, table background-color:
$(".rowBg:even").addClass("rowBgColor");

// User invoices ODD, table background-color:
$("table.table-style tr:odd").addClass("odd-row-bg");


// Round corners class
$(".round6").corner("6px");
$(".round7").corner("7px");
$(".round8").corner("8px");
$(".round9").corner("9px");
$(".round10").corner("10px");
$(".roundTip").corner("round tl bl br 10px");


// User Login forms effect.
$(".user_login2").addClass("user_login").focus(function(){
	$(".user_login2").toggleClass("user_login_focus");
    }).blur(function(){
   	$(".user_login2").removeClass("user_login_focus");
    });

$(".user_pass2").addClass("user_pass").focus(function(){
	$(".user_pass2").toggleClass("user_pass_focus");
    }).blur(function(){
   	$(".user_pass2").removeClass("user_pass_focus");
    });
    
//<fancybox>
$("a.zoom").fancybox();
//</fancybox>


}); //on document ready


//jquery functions
function updateGalleryPicture(theImage){

$("#picture_medium").html(theImage).show();

}

function getAttributes(id_val,lang_val,class_val,k_val,v_val){

var url = "index.php?lang=" + lang_val + "&class=" + class_val + "&action=showAttributes&id=" + id_val;

$.post(url, {k : k_val, v : v_val}, function(result){
    
       $("#attributes").html(result).show();
       
});

}

//library functions
function print(url){
  var load = window.open("index.php?" + url,"","scrollbars=no,menubar=yes,height=0,width=0,resizable=yes,toolbar=no,location=0,status=0");
}

  
function printPage() {

if(window.print)
 window.print();
   
}

function setCookie(c_name,value,expiredays){

var exdate = new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name + "=" + escape(value) +
((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());

}

function textCounter(field,cntfield,maxlimit){

if (field.value.length > maxlimit)
 field.value = field.value.substring(0, maxlimit);
else
 cntfield.value = maxlimit - field.value.length;

}

function updateInstalments(currencyRelation){

//<getting values>
var price = $('#total_price').val();
var prepayment = $('#prepayment').val();
var installmentsPeriod = $('#installments_period').val();
//</getting values>

//<percent>
if(price >= 20000/currencyRelation)
 var percentToAddPerYear = 0.199;
else
 var percentToAddPerYear = 0.219;
//</percent>

//<business logic>
var prepaymentPrice = price*prepayment/100;
prepaymentPrice = Math.round(prepaymentPrice*100)/100;

var maxMonths = (price - prepaymentPrice)/100*currencyRelation;

if(maxMonths > 48)
 maxMonths = 48;

if(maxMonths < installmentsPeriod)
 installmentsPeriod = maxMonths;

var monthlyInstallment = (price - prepaymentPrice) * (1 + percentToAddPerYear*installmentsPeriod/12)/installmentsPeriod;
monthlyInstallment = Math.round(monthlyInstallment*100)/100;
//</business logic>

//<new options for instalment period>
var newOptions = "";

for(i=6;i<=maxMonths;i+=6){

if(installmentsPeriod >= i && (installmentsPeriod - 6) <= i)
 var current = 'selected';
else
 var current = '';

 newOptions += '<option ' + current + ' value="' + i + '">' + i + ' kuud</option>';

}//for
//</new options for instalment period>

$('#installments_period').children().remove().end().append(newOptions);

//<setting results>
$("#prepayment_price").val(prepaymentPrice);
$("#monthly_installment").val(monthlyInstallment);
//</setting results>

}



/* CODA BUBLE */
 $(function () {
        $('.bubbleInfo-tooltip').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 500;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger-tooltip', this);
            var info = $('.popup-tooltip', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: -100,
                        left: -100,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    });
