/*
 *
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Version 2.0
 * Demo: http://www.texotela.co.uk/code/jquery/newsticker/
 *
 * $LastChangedDate$
 * $Rev$
 *
 */
 
(function($) {
/*
 * A basic news ticker.
 *
 * @name     newsticker (or newsTicker)
 * @param    delay      Delay (in milliseconds) between iterations. Default 4 seconds (4000ms)
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @example  $("#news").newsticker(); // or $("#news").newsTicker(5000);
 *
 */
$.fn.newsTicker = $.fn.newsticker = function(delay)
{
    delay = delay || 4000;
    initTicker = function(el)
    {
        stopTicker(el);
        el.items = $("li", el);
        // hide all items (except first one)
        el.items.not(":eq(0)").hide().end();
        // current item
        el.currentitem = 0;
        startTicker(el);
    };
    startTicker = function(el)
    {
        el.tickfn = setInterval(function() { doTick(el) }, delay)
    };
    stopTicker = function(el)
    {
        clearInterval(el.tickfn);
    };
    pauseTicker = function(el)
    {
        el.pause = true;
    };
    resumeTicker = function(el)
    {
        el.pause = false;
    };
    doTick = function(el)
    {
        // don't run if paused
        if(el.pause) return;
        // pause until animation has finished
        el.pause = true;
        // hide current item
        $(el.items[el.currentitem]).fadeOut("slow",
            function()
            {
                $(this).hide();
                // move to next item and show
                el.currentitem = ++el.currentitem % (el.items.size());
                $(el.items[el.currentitem]).fadeIn("slow",
                    function()
                    {
                        el.pause = false;
                    }
                );
            }
        );
    };
    this.each(
        function()
        {
            if(this.nodeName.toLowerCase()!= "ul") return;
            initTicker(this);
        }
    )
    .addClass("newsticker")
    .hover(
        function()
        {
            // pause if hovered over
            pauseTicker(this);
        },
        function()
        {
            // resume when not hovered over
            resumeTicker(this);
        }
    );
    return this;
};

})(jQuery);

$(function() {
        / * basic curve on divs */
    $("#main, #main-product, #main-news, #product-list, #main-features, #main-support, #container-pedrox, #container-curvo").corners("9px transparent bottom");
    $("#col1, #col2, #col3").corners("8px bottom");
    $("#rightnav, .maintenance").corners("9px bottom-left");
    $("#specification-data thead th:first-child").livequery(function() {
        $(this).corners("11px top-left");
    });
    $("#specification-data thead th:last-child").livequery(function() {
        $(this).corners("11px top-right");
    }); 
    $("#specification-data tbody tr:odd").livequery(function() {
        $(this).addClass("alternate-row");
    });

    /* product scroll and its animations */
    $("#product-list").jMyCarousel({
        eltByElt: true,
        evtStart: 'mousedown',
        evtStop: 'mouseup',
        visible: '902px'
    });
    $("input.next, input.prev").hide();
    $("#product-list").hover(function() {
        $("input.next, input.prev").fadeIn("fast");
    }, function() {
        $("input.next, input.prev").fadeOut("fast");
    });
    
    $("ul#product-item > li > a").click(function() {
        var link_to = $(this).attr("href");
        if ($("#main-product").length > 0) {
            $.get(link_to, function(data) {
                $("#main-product").children().remove();
                $(data).appendTo("#main-product").fadeIn();
            });
        } else
            exit;
        return false;
    });
    
    $("#product-nav > ul > li > a").livequery('click', function() {
        var link_to = $(this).attr("href");
        $("#main-product").children().remove();
        $.get(link_to, function(data) {     
            $(data).appendTo("#main-product").fadeIn();
            if ($("a[rel^='gallerybox']").length > 0)
                $("a[rel^='gallerybox']").galleryBox();
        });
        return false;
    });

    /* Features Navigation */
    $(".feature-content:not(:first)").hide();
    $("#features-description h2").click(function() {
        var item = $(this).parent().attr("id");
        
        $("#features-image > img").removeAttr("src");
        $(".feature-content:visible").slideUp("fast");
        $("h2.expand").removeClass("expand").addClass("collapse");
        $(this).parent().find("h2").removeClass("collapse").addClass("expand");

        $("#features-image > img").attr("src", "http://media\.gardio\.co\.id/images/"+item+".png").fadeIn("slow");
        $(this).next().slideDown("fast");
        return false;
    });
    $('#news').newsticker();
});
