// JavaScript Document
function imgSwap(oImg)
{
   var strOver  = "_on"    // image to be used with mouse over
   var strOff = "_off"     // normal image
   var strImg = oImg.src
   if (strImg.indexOf(strOver) != -1) 
      oImg.src = strImg.replace(strOver,strOff)
   else
      oImg.src = strImg.replace(strOff,strOver)
}

    $(document).ready(function() {
            /*
            *   Examples - images
            */

            $("a[rel=leg_finishes]").fancybox({
                'transitionIn'        : 'none',
                'transitionOut'        : 'none',
                'titlePosition'     : 'over',
                'titleFormat'        : function(title, currentArray, currentIndex, currentOpts) {
                    return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
                }
            });
            
                $("a[rel=chair_finishes]").fancybox({
                'transitionIn'        : 'none',
                'transitionOut'        : 'none',
                'titlePosition'     : 'over',
                'titleFormat'        : function(title, currentArray, currentIndex, currentOpts) {
                    return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
                }
            });
            $("a[rel=homepop]").fancybox({
                'padding'        : '0',
                'frameWidth' : '0',
                'showCloseButton' : '0'
    });
        
                $(".brands_left a").mouseover(function() {
                    $("#brand_photo").fadeOut(0);
                    var path = $(this).attr("alt");
                    var full_path = "<img src=\"images/" + path + ".jpg\" />";
                        $('#brand_photo').html(full_path).fadeIn(300);
                    });
    
    $('#poster').cycle({ 
            fx:         'fade', 
            timeout:     5000, 
            pager:      '#image-items',
            prev:    '#prev',
            next:    '#next',
            pagerEvent: 'click',
            before:    function(currSlideElement, nextSlideElement, options, forwardFlag) {
                    $('#detail-container').fadeOut();
                    var TheImage = $(nextSlideElement).attr('rel');
                    var TheURL = "get-details.php?id=" + $(nextSlideElement).attr('id');
                    $('#whatImage').empty().html(TheImage);
                    $('#show-details').attr('href',TheURL);
                    },
            pause: 1, 
            fastOnEvent: true 
        });
        
        $('#poster-home').cycle({ 
            fx:         'fade', 
            timeout:     5000, 
            pager:      '#image-items',
            prev:    '#prev',
            next:    '#next',
            pagerEvent: 'click',
            before:    function(currSlideElement, nextSlideElement, options, forwardFlag) {
                        $('#detail-container').fadeOut();
                        var TheImage = $(nextSlideElement).attr('rel');
                        var TheURL = "get-details.php?id=" + $(nextSlideElement).attr('id');
                        if($(nextSlideElement).attr('id')=='i0') {
                            $('#sha').addClass('hm');
                        } else {
                            $('#sha').removeClass('hm');
                        }
                        $('#whatImage').empty().html(TheImage);
                        $('#show-details').attr('href',TheURL);
                        },
            pause: 1, 
            fastOnEvent: true 
        });
        
        
        
        $('#poster-home').mouseover(function(){
            $('#poster-home').cycle('pause');
        })
        
         $('#poster-home').mouseout(function(){
                $('#poster-home').cycle('pause');
            })
        
            
        $('#detail-container').hide();
        
        $('#detail-container').mouseover(function(){
            $('#poster').cycle('pause');
        });
        
            
        $('#image-items a').click(function() {
            $('#poster').cycle('pause');});
            
        $('#show-details').click(function() {
            var url = "";
            $('#poster').cycle('pause');
            var url = $(this).attr('href');
            //var url = 'get-details.php?id='+id;
            //$('#detail-content').empty();
            $.ajax({
                  url: url,
                  success: function(data) {
                    var patt = /falsch/gi;
                    if(!data.match(patt)) {
                        $('#detail-content').html(data);
                        $('#detail-container').fadeIn();
                    }
                  }
            });
            return false;
        });        
        });
        
        function closeDetails() {
        $('detail-container').setStyle('display', 'none');}
        
        function toggleNav() {
    
    $('#nav_open').toggle();
}

    window.addEvent('domready', function(){
        $('sha').addEvent('click',function(e) {
            $('show-details').setStyle('display', 'block');
            return false;        
        });
    });
    
    function closeDetails() {
        $('#detail-container').css('display', 'none');
        return false;
    }
    
    function closeShowDetails() {
            $('show-details').setStyle('display', 'none');}
            
    function ChangePhoto (oldimg, newimg) {

   document.images[oldimg].src=newimg;

}




/* LI HOVER FUNCTION *** ADDED 2011-08 BY SAMIR JOZA */
function hover_li(cls,addcls) {
    $("li." + cls ).hover(
        function(){
            $(this).addClass(addcls).fadeIn("slow");
        },
        function() {
            $(this).removeClass(addcls);
        }
    );
}  
