function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};        

$(function() {
    $('.connect_widget_text_summary').css('color','#ffffff');

    $.metadata.setType("attr", "validate");

    $("#acc").validate({
        rules: {                        
          pass2: { equalTo: "#pass1" }        
        }    
    });
    
    $("#reg").validate({
        rules: {                        
          pass2: { equalTo: "#pass1" }        
        }    
    });
    
    $(".confirm").easyconfirm();

    $('a.ext').click(function() {
      window.open(this.href);
      return false;
    });
    
		$( "a.print" )
      .attr( "href", "javascript:void( 0 )" )
			.click(
				function(){
					// Print the DIV.
					$( ".printable" ).print();

					// Cancel click event.
					return( false );
				}
			);    
			
		$('a.email').click(function(e) {
			e.preventDefault();
			var $this = $(this);
			var horizontalPadding = 30;
			var verticalPadding = 30;
	        $('<iframe id="newsByEmail" class="newsByEmail" src="' + this.href + '" />').dialog({
	            title: ($this.attr('title')) ? $this.attr('title') : 'Send by email',
	            autoOpen: true,
	            width: 322,
	            height: 151,
	            modal: true,
	            resizable: false,
				autoResize: true,
	            overlay: {
	                opacity: 0.5,
	                background: "black"
	            }      
	        }).width(322 - horizontalPadding).height(151 - verticalPadding);	        
		});			

    $('#menu li').last().addClass('last');
    
    $("a[rel^='prettyPhoto'],a.box").prettyPhoto({theme:'facebook'});

    $("#featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
    
    $('#featured li').last().css('background','none');
    $('#featured li').last().css('padding-bottom','0');
        
    
    $('#bottomMenu li a').hover(
      function () {
        $(this).css('background-position','0 -88px');
      },
      function () {
        $(this).css('background-position','0 0');
      }
    );
    
    $('#banner li a').hover(
      function () {
        $(this).css('background-position','0 -73px');
      },
      function () {
        $(this).css('background-position','0 0');
      }
    );
    
    $('#bottomLogo li a').hover(
      function () {
        $(this).css('background-position','0 -62px');
      },
      function () {
        $(this).css('background-position','0 0');
      }
    );                    
    
    jQuery('#mycarousel').jcarousel({
        auto: 3,
        wrap: 'circular',
        scroll: 1,
        animation: "slow",
        initCallback: mycarousel_initCallback
    });
    
    $("#search-box select, #search-box input:submit, #login-box input:text, #login-box input:password, #order input:submit, #order select, .profile .w input:submit, .profile .w select, .profile .w input[type=file], #reg input[type=text],#reg input[type=password],#reg input[type=submit]").uniform();
                         
    $('#newsletter input[type="text"]').focus(
      function() {
        this.value = '';                                       
      }); 
      
    $('#newsletter input[type="text"]').blur(
      function() {
        this.value = this.defaultValue;                                       
      });
                                        
    $('#gallery li').each(function() {
      imgWidth = $(this).find('img').width();
      imgHeight = $(this).find('img').height();      
                                              
      if(imgWidth < imgHeight) {
        $(this).addClass('v');
      } else {
        $(this).addClass('s');
      }      
    });
    
    $('#gallery li').hover(function() {
        var t = $(this).find('img');                                     
        t.attr('src',t.attr('src').replace('-gray', ''));                                 
    },function() {
        var t = $(this).find('img');                                     
        t.attr('src',t.attr('src').replace(/([^.]*)\.([^.]*)\.([^.]*)\.(.*)/, '$1.$2.$3-gray.$4'));    
    });     
    
    $('.fotoBox a').hover(function() {
        var t = $(this).find('img');                                     
        t.attr('src',t.attr('src').replace('-gray', ''));                                 
    },function() {
        var t = $(this).find('img');                                     
        t.attr('src',t.attr('src').replace(/([^.]*)\.([^.]*)\.([^.]*)\.(.*)/, '$1.$2.$3-gray.$4'));    
    });         
    
    $("#tabs").tabs();
    
    $('#newsletter input[type="submit"]').hover(function() {
        $(this).css('background-position','0 -125px');
    },function() {
        $(this).css('background-position','0 -100px');
    } );
    
    function switchText()
    {
    	if ($(this).val() == $(this).attr('title'))
    		$(this).val('').removeClass('exampleText');
    	else if ($.trim($(this).val()) == '')
    		$(this).addClass('exampleText').val($(this).attr('title'));
    }
    
    $('input[type=text][title!=""],textarea[title!=""]').each(function() {
    	if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
    	if ($(this).val() == $(this).attr('title')) $(this).addClass('exampleText');
    }).focus(switchText).blur(switchText);
    
    $('form').submit(function() {
    	$(this).find('input[type=text][title!=""],textarea[title!=""]').each(function() {
    		if ($(this).val() == $(this).attr('title')) $(this).val('');
    	});
    });
    
});
                  
