// Define variables

// Ready
jQuery().ready(function() {
    // Background
    $.fn.supersized.options = {
        startwidth: 800,
        startheight: 500,
        vertical_center: 1,
        slideshow: 0
    };
    $('#supersize').supersized();

    // Navigation - show or hide submenu
    $('#header ul ol').each(function() {
        var master = $(this).parent();
        var link = $('a:first', master );

        link.click(function() {
            var parent = $(this).parent();
            var element = $('ol', parent);
            $('#header ul ol').fadeOut();
            $('#header ul a.active').removeClass('active');

            if (element.css('display') == 'none')
            {
                $(this).addClass('active');
                element.fadeIn();
            }
        });
    });
    $('#header ul a.active').each(function() {
        var parent = $(this).parent();
        $('ol', parent).fadeIn('slow');
    });

    // Change backgrounds
    $('#change_background a, .change_background a').click(function() {
        var image = $(this).attr('href');
        var put_there = $('#supersize img');

        put_there.fadeOut('slow', function() {
            put_there.attr('src', image).load(function() {
                put_there.fadeIn('slow');
            });
        });
        
        return false;
    });

    // Pretty Photo Plugin
    $("a[rel^='prettyPhoto']").prettyPhoto();

    // Scroll
    $('#categories li a').click(function() {
        var go_to = $(this).attr('href');
        var destination = $(go_to).offset().top;
        
        $("#wrapper:not(:animated)").animate({ scrollTop: destination}, 1000);
        return false;
    });

    // Make it transparent
    $('.make_it_transparent').css('opacity', '0.3');

    // Goto Up
    $('#go_up').click(function() {
        var destination = $('#header');
        $("#wrapper:not(:animated)").animate({ scrollTop: destination}, 1000);
        return false;
    });
	
	// Add google maps (with javascript because give wrong map with some of javascripts)
	//$("#google_maps").prepend('<iframe width="790" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://www.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;t=h&amp;msa=0&amp;msid=116004496297430898066.00047b410566517498aaf&amp;ll=42.668032,23.292732&amp;spn=0.005522,0.013754&amp;z=16&amp;output=embed"></iframe>');
});


function add_or_remove_in_basket(el, id)
{
    if (el && id)
    {
        el = $(el);
        $.getJSON(_root + 'application/xhr', {method: 'add_or_remove_in_basket', item: id},
            function(data){
                if (data.status == 1)
                {
                    el.addClass('checked');
                }
                else
                {
                    el.removeClass('checked');
                }
            }
        );
    }

    return false;
}
