/* === SET GLOBALS === */

    var current = 0;
    var num_thumbs;
    var thumb_width = 81;
    var thumbs_per_clip = 4;


/* === SLIDER FUNCTIONS === */

    function slide(current) {
        var o = document.getElementById("thumbs");
        var a = new Accelimation( o.style, "left", -(current * thumb_width), 500, 0.5);
            a.onend = new Function("void(0);");
            a.start();
    }

    function moveright() {
        if (current < num_thumbs - thumbs_per_clip) {
            current++;
            slide(current);
        }
    }

    function moveleft() {
        if (current > 0) {
            current--;
            slide(current);
        }
    }


/* === SWAP FUNCTIONS === */

    function getElementsByClass(node,searchClass,tag) {
        var classElements = new Array();
        var els = node.getElementsByTagName(tag); // use "*" for all elements
        var elsLen = els.length;
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");

        for (i = 0, j = 0; i < elsLen; i++) {
            if ( pattern.test(els[i].className) ) {
                classElements[j] = els[i];
                j++;
            }
        }
        return classElements;
    }

    function show(num) {
        if (document.getElementById("gift" + num)) {
            if (document.getElementById("product_intro") || document.getElementById("product_intro") != null)
                document.getElementById("product_intro").style.visibility = "hidden";
            for (var i = 0; i < getElementsByClass(document,"gift","div").length; i++) {
                document.getElementById("gift" + i).style.visibility = "hidden";
            }
            document.getElementById("gift" + num).style.visibility = "visible";
        }
    }

/* === DETAILS VIEW === */

    function viewProduct(id) {
        popUpWindow('/valentines/products/view-product.asp?id='+id,'hhp'+id,420,410,'no');
    }

    function popUpWindow(cPopUrl, cPopName, iPopWidth, iPopHeight, bScrollBars) {
    //cPopUrl = the name of url to call, bScrollBars = if 'no' or blank, no bars will appear.
    	var iPopLeft, iPopTop;
    	var oPopWindow = null;
    	if (!oPopWindow || oPopWindow.closed){
    		//Center popup window inside parent window.
    		iPopLeft = (window.screen.width/2) - ((iPopWidth/2) + 10);
    		iPopTop = (window.screen.height/2) - ((iPopHeight/2) + 50);
    		//Open popup window
    		oPopWindow=open(cPopUrl, cPopName,"height="+ iPopHeight +",width="+ iPopWidth +",left=" + iPopLeft + ",top=" + iPopTop + ",screenX=" + iPopLeft + ",screenY=" + iPopTop + ",scrollbars=" + bScrollBars + ", statusbar=no");
    		oPopWindow.location.href = cPopUrl;
    		oPopWindow.focus()
        }
    	else {
        	oPopWindow.focus()
    	}
    }



/* === INITIALIZE === */

    function init() {
        num_thumbs = document.getElementById("thumbs").getElementsByTagName("span").length;
    }

    window.onload = init;