$(document).ready(function() {
// modal window
/*
<div class="modal">
		
	<div class="modal-container">
		<div id="modalHeader"></p>
		<div id="modalContent"></p>
		<div id="modalButtons"></p>
	</div>
	
	<div class="modal-mask"></div>

</div>
 */
	
	//select all the a tag with name equal to modal
    $( 'a.deleteAddress' ).click( function(e) {
 
        e.preventDefault();
              
        var deleteUrl = $(this).attr('href');

        $('#modalHeader').html('Are you sure?');
        
        $('#modalContent').html('This action cannot be undone. If you want to delete this address, then click \'continue\'.');
        
        buttonConfirm = $('<a id="modalButtonConfirm"></a>');
        buttonConfirm.html('continue');
        buttonConfirm.addClass('button');
        buttonConfirm.css('margin', '0px 20px');
        buttonConfirm.click( function(){
        	window.location = deleteUrl;
        });
        
        
        buttonCancel = $('<a id="modalButtonCancel"></a>');
        buttonCancel.html('cancel');
        buttonCancel.addClass('button');
        buttonCancel.css('margin', '0px 20px');
        buttonCancel.click( function(){
        	hideModal();
        });
        
        $('#modalButtons').html( buttonConfirm ).show();
        $('#modalButtonConfirm').after( buttonCancel );
        
        showModal();
    });

    $( '#closeModal' ).click( function (e) {
        e.preventDefault();
        hideModal();
    });    
     
    $( '#modalMask' ).click( function (e) {
    	e.preventDefault();
    	hideModal();
    });    


    
    
// initialize scrollable

	$(".scrollable").scrollable({
		circular: true,
		speed: 700
	}).navigator().autoscroll({
		autoplay: true,
		interval: 4000
	});


	$("ul.product-thumbs li").each( function() {
		if ( !$( this ).hasClass( 'selected' ) ) {
			$( this ).fadeTo( 'medium', 0.6 );
		}
	});
	
	$("ul.product-thumbs li a").hover( function() {
		$( this ).parent().fadeTo( 'medium', 1.0 );
	}, function() {
		if( !$( this ).parent().hasClass( 'selected' ) ) {
			$( this ).parent().fadeTo( 'medium', 0.6 );
		}
	});
	
	$("ul.product-thumbs a").click( function( e ) {
		e.preventDefault();
		$( this ).parent().siblings().removeClass( 'selected' );
		$( this ).parent().addClass( 'selected' );
		$( this ).parent().siblings().fadeTo( 'medium', 0.6 );
		$('#product-image').attr( 'src', '/images/products/images-large/' + $(this).attr( 'data-filename' ) );
		$('#product-image').parent('a').attr( 'href', '/images/products/images-full/' + $(this).attr( 'data-filename' ) );
		
	});
	

});

function hideModal(){
	 $( '#modalContainer' ).fadeOut( 500 );
    $( '#modalMask' ).fadeOut( 500 );
}

function showModal(){
   var modal = $( '#modalContainer' );
   
   var maskHeight = $( document ).height();
   var maskWidth = $( window ).width();

   var winH = $( window ).height();
   var winW = $( window ).width();	
   
   $( '#modalMask' ).css({
   	'width':maskWidth,
   	'height':maskHeight
   });

	modal.css( 'top',  window.pageYOffset + winH / 2 - modal.height() / 2 );
   modal.css( 'left', winW / 2 - modal.width() / 2 );
   
	$( '#modalContainer' ).fadeIn( 500 );
   $( '#modalMask' ).fadeTo( 500, 0.8 );
}

function initMenu() {
	$('#product-nav li a.header-item').click(
		function( event )
		{
			event.preventDefault();
			
			if( !$(this).hasClass( 'selected' ) ) {
				$('#product-nav ul').slideUp('normal');
				$(this).next().slideToggle('normal');
				$('#product-nav a').removeClass( 'selected' );
				$(this).addClass( 'selected' );
			}
		}
	);
}

$(document).ready(function() {initMenu();});



function initMenu2() {
	$('#menu ul').hide();
	$('#menu ul:first').show();
	$('#menu li a').click(
	function( event )
		{
			event.preventDefault();
			
			var checkElement = $(this).next();
	
			if((checkElement.is('ul')) && (checkElement.is(':visible')))
			{
				return false;
			}
			
			if( ( checkElement.is('ul')) && (!checkElement.is(':visible')))
			{
				$('#menu ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}

$(document).ready(function() {initMenu2();});

$(function() {
	// Use this example, or...
	$('a.lbImage').lightBox({
	overlayBgColor: '#fff',
	overlayOpacity: 0.6,
	containerResizeSpeed: 350,
	txtImage: 'Imagem'
	});
});

