// Production version.
// Copyright Jacobus Systems Limited 2004-2005.


self.onerror = jslErrorHandler;


function jslErrorHandler(msg, url, line)
{
        alert('Error - ' + msg + ' in ' + url + ' at line ' + line);
}


function jslInitialize()
{
        jslInitRotator();
}


//---------------------------------------------------------------------------------------------------------------------------
// PayPal cart functions.
//---------------------------------------------------------------------------------------------------------------------------

function jslAddCart(business, itemSKU, itemName, itemPrice)
{
        var s;
	s = 'https://www.paypal.com/cart/add=1&business=' + business + '&item_name=' + itemName
                + '&item_number=' + itemSKU + '&currency_code=GBP&amount=' + itemPrice;
	window.open(s, 'cartwin', 'width=780,height=360,scrollbars,location,resizable,status');
	return false;
}

function jslAskQuestion(siteName, businessEmail, itemSKU, itemName)
{
        var to = siteName + " <" + businessEmail + ">";
        var subject = "------Question about item " + itemSKU + ", " + itemName;
        var body = "Dear " + siteName + ",\n\n"
                + "I have a question about item " + itemSKU + ", " + itemName + ".\n"
                + "Would you please tell me the following:\n\n";

        var doc = "mailto:" + to + "?subject=" + escape(subject) + "&body=" + escape(body);

        window.location = doc;
        return false;
}

function jslCheckout(business)
{
        var s;
        s = 'https://www.paypal.com/cart/checkout=1&business=' + business;
	window.open(s, 'cartwin', 'width=780,height=360,scrollbars,location,resizable,status');
	return false;
}

function jslViewCart(business)
{
        var s;
        s = 'https://www.paypal.com/cart/display=1&business=' + business;
	window.open(s, 'cartwin', 'width=780,height=360,scrollbars,location,resizable,status');
	return false;
}


//---------------------------------------------------------------------------------------------------------------------------
// Image Rotator functions.
//---------------------------------------------------------------------------------------------------------------------------

function jslInitRotator()
{
        // Is there a Rotator image on this page?
        if (!document.jslRotateImage)
                return;

//        document.getElementById('jslRotateTable').style.display = 'none';

        jslCurRotateItem = 0;
        jslImagePreload = new Image(400,300);
        jslPrevRotateItem = 0;
        jslRotateHandle = 0;
        jslRotateInterval = 4000;

        // Where are the image files?
        if (window.location == 'about:blank')
                jslImagePath = 'file:///C:/Webs/Astarte/Publish/images/';
        else
                jslImagePath = '../images/';

        // Load the data.
        jslSetupRotator();

        // Show the first item.
        jslNextRotateItem = 0;
        jslShowNextItem();

        // Start the rotation.
        jslStartRotation();
}

function jslPreloadNextItem()
{
        // Preload the next item's image.
        var item = jslRotatorItems[jslNextRotateItem];
        imageFile = jslImagePath + item.image;
        jslImagePreload.src = imageFile;
}

function jslShowItem(index)
{
//        document.getElementById('jslRotateTable').style.display = 'inline';

        jslCurRotateItem = index;
        var item = jslRotatorItems[index];

        // Update the image.
        document.jslRotateImage.src = jslImagePath + item.image;
        a = document.anchors[0];
        a.href = item.url;

        // Update the name.
        a = document.anchors[1];
//        if (a.text)
//                a.text = item.name;		// Netscape 4
//        else
                a.innerText = item.name;        // IE 4
        a.href = item.url;

        // Update the description.
        a = document.anchors[2];
//        if (a.text)
//                a.text = item.description + ' ' + item.price;		// Netscape 4
//        else
                a.innerText = item.description + ' ' + item.price;      // IE 4
}

function jslShowNextItem()
{
        jslShowItem(jslNextRotateItem);

        // Sort out the next item.
        jslNextRotateItem = jslCurRotateItem + 1;
        if (jslNextRotateItem >= jslRotateCount)
                jslNextRotateItem = 0;

        // Preload the next item.
        jslPreloadNextItem();
}

function jslShowPrevItem()
{
        jslPrevRotateItem = jslCurRotateItem - 1;
        if (jslPrevRotateItem < 0)
                jslPrevRotateItem = jslRotateCount - 1;

        jslShowItem(jslPrevRotateItem);
}

function jslStartRotation()
{
        // Setup the controls.
        document.getElementById('prev_button').style.display = 'none';
        document.getElementById('start_button').style.display = 'none';
        document.getElementById('stop_button').style.display = 'inline';

        // Setup the timer.
        jslRotateHandle = setInterval('jslShowNextItem()', jslRotateInterval);
}

function jslStopRotation()
{
        // Stop the timer.
        clearInterval(jslRotateHandle);

        // Setup the controls.
        document.getElementById('prev_button').style.display = 'inline';
        document.getElementById('start_button').style.display = 'inline';
        document.getElementById('stop_button').style.display = 'none';
}


