$( document ).ready( function (){
    $.hoveImage = 'false';
    $('a.close').click(function(){
        $('#top-navigator').fadeOut();
    });

    $('div.description').each(function(){
        //..set width same as the image...
        $(this).css('width', $(this).siblings('img').width());
        //...get the parent (the wrapper) and set it's width same as the image width... '
        $(this).parent().css('width', $(this).siblings('img').width());
        //...set the display to block
        $(this).css('display', 'block');
    });

    $('div.wrapper').hover(function(){
        //when mouse hover over the wrapper div
        //get it's children elements with class description '
        //and show it using fadeTo
        $(this).children('.description').stop().fadeTo(500, 0.5);
    },function(){
        //when mouse out of the wrapper div
        //use fadeTo to hide the div
        $(this).children('.description').stop().fadeTo(500, 0.2);
    });

    $('.product-items li').hover(function(){
        //$(this).parents('div.wrapper').children('img.bg-product').attr('src',$(this).attr('rel')).fadeIn('fast');
        if($.inAnimation) return false;
        productImageHover($(this));
        return false;
    });
}
);

$(document).ready(function() {
    var speed = 5000;
    $('#mask-gallery, #gallery li').width($('#slider').width());
    $('#gallery').width($('#slider').width() * $('#gallery li').length);
    var run = setInterval('newsslider(0)', speed);
    $('#next').click(function () {
        newsslider(0);
        return false;
    });
    $('#prev').click(function () {
        newsslider(1);
        return false;
    });
    $('#slider').hover(
        function() {
            clearInterval(run);
        },
        function() {
            run = setInterval('newsslider(0)', speed);
        }
        );
    $('.image-navigation h3').html($('#gallery li:first').find('img').attr('title'));
    $('.image-navigation p').html($('#gallery li:first').find('img').attr('alt'));
    $('.image-navigation a').attr('href', $('#gallery li:first').find('a').attr('href'));
    Cufon('.cufon-gallery');
    $('#logo').flash({
        swf: BASE_URI+'songthum.swf',
        width: 670,
        height: 100,
        wmode: 'transparent'
    });

    $('#catelog-swf').flash({
        swf: BASE_URI+'catelog.swf',
        width: 750,
        height: 120,
        wmode: 'transparent'
    });
});


function newsslider(prev) {
    var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
    if (prev) {
        var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
    } else {
        var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
    }
    $('#excerpt li, #gallery li').removeClass('selected');
    next_image.addClass('selected');
    $('#mask-gallery').scrollTo(next_image, 800);
    $('.image-navigation h3').html($(next_image).find('img').attr('title'));
    $('.image-navigation a').attr('href', next_image.find('a').attr('href'));
    $('.image-navigation p').html($(next_image).find('img').attr('alt'));
    Cufon('.cufon-gallery');
}

function productImageHover($element){
    if($.inAnimation) return false;
    else $.inAnimation = true;
    $element.parents('div.wrapper').children('img.bg-product').attr('src',$element.attr('rel'));
    $.inAnimation = false;
}

$(document).ready(function(){
    $('.rollover').hover(function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    }, function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    });
});
