/* init */
$(document).ready(function(){

    // Adding classes for old browsers and also a backup in case of forgetting
    $('table').attr('cellspacing', '0');
	$('form, div.gallery').addClass('clearfix');
	//$('form p').addClass('fieldWrapper');
	$('input:text').addClass('input-text');
	$('input:password').addClass('input-password');
	$('input:submit').addClass('input-submit');
	$('input:checkbox').addClass('input-checkbox');
	$('input:radio').addClass('input-radio');
    $('.shops tr td:last-child').addClass('last-td');
    
    // Tips
    $('#tooltips p').wrap('<div><span class="tip"></span></div>');
    $('#tooltips div').addClass(function() {
        return 'nr-' + $(this).index();
    });
    $('#tooltips .tip').prepend('<em class="arr" />');
    /*$('#tooltips .nr-0 .tip').prepend('<em class="nr">1</em>');
    $('#tooltips .nr-1 .tip').prepend('<em class="nr">2</em>');
    $('#tooltips .nr-2 .tip').prepend('<em class="nr">3</em>');
    $('#tooltips .nr-3 .tip').prepend('<em class="nr">4</em>');
    $('#tooltips .nr-4 .tip').prepend('<em class="nr">5</em>');
    $('#tooltips .nr-5 .tip').prepend('<em class="nr">6</em>');
    $('#tooltips .nr-6 .tip').prepend('<em class="nr">7</em>');
    $('#tooltips .nr-7 .tip').prepend('<em class="nr">8</em>');
    $('#tooltips .nr-8 .tip').prepend('<em class="nr">9</em>');
    $('#tooltips .nr-9 .tip').prepend('<em class="nr">10</em>');
    $('#tooltips .nr-10 .tip').prepend('<em class="nr">11</em>');
    $('#tooltips .nr-11 .tip').prepend('<em class="nr">12</em>');
    $('#tooltips .nr-12 .tip').prepend('<em class="nr">13</em>');*/
    
    $('#tooltips .tip strong:first-child').addClass('nr');
    
    // Tip hover
    $('.inside-view div').hover(function() {
        $(this).find('.tip').addClass('show');
        Cufon.replace('.tip strong', {
            color: '#fff'
        });
    },function() {
        $(this).find('.tip').removeClass('show');
    });
    
    // Left-menu hover
    $('div.menu li').hover(function() {
        $(this).find('ul').addClass('show');
        //$('ul:first',this).css('display', 'block');
    },function() {
        $(this).find('ul').removeClass('show');
        //$('ul:first',this).css('display', 'none');
    });
    
    // Add class to body depending on viewport height
    $(".main-bg").css('min-height', ($("html").height() + 1) + "px");
    
    // PRODUCT JS
    // wraps all gallery-thumbs on the product page inside a span
    $('.product .gallery .gallery-icon img').wrap('<span class="img-wrap"></span>');
    
    // White overlay if thumb is selected (clicked)
    // $('.product-thumbs .gallery .gallery-icon').prepend('<span class="overlay"></span>');
    
    // for testing fancybox
    //$('.product .left-col img:first').wrap('<a href=""></a>');
    //$('.product .left-col a:has(img)').attr("id", "fancy_photo");
    
    $('.left-col').prepend($('<a href="" id="product_image"><img /></a>'));
    
    $('.left-col a:has(img), .product-thumbs a:has(img), #textile a:has(img)').attr('rel', 'fancy-image');
    
    // Fancybox for product left-col image
    $("a[rel=fancy-image]").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titleShow': false,
        'titlePosition': 'over',
        'overlayOpacity': '0.5',
        'overlayColor': '#000'
    });
    // #product_image
    
    $('#product_thumbs img').filter(':first').trigger('click');
    
    $('.textiles .gallery-icon a').click(function() {
        return false;
    });
    
    // Fancybox for other galleries - add :not for product pages
    $('.gallery-icon a:not(.product .gallery-icon a)').fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titleShow': false,
        'titlePosition': 'over',
        'overlayOpacity': '0.5',
        'overlayColor': '#000'
    });
    
});
