 /**
  * katalog.js
  *
  * @package   web.js.katalog
  * @author    Gruber David <gruber.david@gmail.com>
  * @copyright 2007-2010 ScooterTech GmbH
  */
$(document).ready(function() {
    /* item image viewer */
    if($("#images").size() > 0) {
        $("#images .preview").click(function(e){
            $("#images .preview").removeClass("focused");
            $(this).addClass("focused");
            
            var old_src = $(this).attr("src");
            var size = 'standard';
            
            $.each( $(this).attr("class").split(" "), function(i, clas){
                if(clas.substring(0, 5) == 'size-') {
                    size = clas.substring(5);
                }
            });
            
            $("#images .image").attr("src", old_src.replace(/small/, size));
            $("#images a").attr("href", old_src.replace(/small/, 'original'));
        });
    }
    
    /* search */
    $(".more-results").click(function(e) {
        $(this).hide()
               .parents(".results-section").next().toggle();

        return false;
    });
    $(".less-results").click(function(e) {
        $(this).parents(".results-section-more").hide()
               .prev(".results-section").find(".more-results").show();

        return false;
    });

    /* frontpage: latestItems */
    if($("#latest-items .item-page:visible").next(".item-page").length > 0) {
        $("#latest-items .next-items").show();
    }
    $("#latest-items .navigation a").click(function(e) {
        var oldItemPage = $("#latest-items .item-page:visible").hide();
        
        if($(e.target).hasClass("prev-items")) {
            oldItemPage.prev().show();
        } else if($(e.target).hasClass("next-items")) {
            oldItemPage.next().show();
        }

        $("#latest-items .navigation a").show();
        if($("#latest-items .item-page:visible").prev(".item-page").length == 0 ||
           $("#latest-items .item-page:visible").next(".item-page").length == 0) {
            $(e.target).hide();
        }

        return false;
    });

    /* vehicle_list */
    $(".vehicle a").hover(function(){
        $(this).next("span").show();
    }, function() {
        $(this).next("span").fadeOut(250);
    });
    
    /* toggle visibility of object section */
    $(".toggle_section ul").hide();
    
    $(".show_section").click(function(e){
        e.preventDefault();
        $(this).siblings("ul").toggle();
    });

    $(".show_motor_information").click(function(e){
        e.preventDefault();
        $(".motor_information").show();
        $(this).hide();
    });
    $(".show_vehicle_information").click(function(e){
        e.preventDefault();
        $(".vehicle_information").show();
        $(this).hide();
    });
});
