function slideSwitch() {
    var $active = $('div#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('div#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('div#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});



$(document).ready(function(){

//bottom decorator - scroll up
$("#top").click(function(){
   $("html, body").animate({scrollTop:0}, "fast"); 
});


//3rd subcategory margin 0
$(".subCats:eq(2)").css("margin-right",0);

//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);


// Fade images: class="fade"
$(".fade").css("opacity",0.4).mouseover(function(){
	$(this).fadeTo("fast",1);
    }).mouseout(function(){
   	$(this).fadeTo("fast",0.4);
    });

//Fade buttons
$(".button").css("opacity",0.70).mouseover(function(){
	$(this).fadeTo("fast",1);
    }).mouseout(function(){
   	$(this).fadeTo("fast",0.70);
    });

// 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");
    });

$("div.productNames").css("opacity",0.50);




}); //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();
       
});

}

function getGallery(status,lang_val){

var url = "index.php?lang=" + lang_val + "&class=gallery&action=getPicture&sid=" + Math.random();

$.post(url, {"status" : status}, function(result){

       $("#gallery").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 swapImages(id){

var pictureOne = $('#picture0').html();
var pictureTwo = ($('#picture' + id).html());

$("#picture0").html(pictureTwo).show();
$("#picture" + id).html(pictureOne).show();

}


/* 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;
            });
        });
    });
 
 


        window.onload = function () {
            var container = $('div.sliderGallery');
            var ul = $('ul', container);
            
            var itemsWidth = ul.innerWidth() - container.outerWidth();
            
            $('.slider', container).slider({
                min: 0,
                max: itemsWidth,
                handle: '.handle',
                stop: function (event, ui) {
                    ul.animate({'left' : ui.value * -1}, 500);
                },
                slide: function (event, ui) {
                    ul.css('left', ui.value * -1);
                }
            });
        };

		
		

