$(document).ready(function() {
	
	$("#body-background").ezBgResize();

	
	$("#gallery div:last").css({margin:0});
	$("#gallery").smoothDivScroll({ 
		scrollStep: 3, 
		scrollInterval: 8, 
		mouseDownSpeedBooster:	3,
		visibleHotSpots: "always",
		hotSpotsVisibleTime: 1000
	});$('.scrollableArea').width(2000);
	$("#gallery div").css({opacity:1, display:'block'});
	
/*
	$('#fighter-gallery').cycle({ 
	    fx: 'scrollHorz',
	    speed: 1500,
	    timeout: 0,
	    next:   '.next', 
	    prev:   '.prev',
            after:   onAfter,
	    easing: 'easeInOutQuint',
	    cleartype:       true  // true if clearType corrections should be applied (for IE) 
	});

        function onAfter(curr, next, opts) {
            var index = opts.currSlide;
            $('.prev')[index == 0 ? 'hide' : 'show']();
            $('.next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
        }
*/

		$('#fighter-gallery').jcarousel({
            scroll:5,
            visible:5,
            wrap:null,
            buttonPrevHTML:'<a href="javascript:void(0)" class="prev"><img src="/engines/commons/images/prev.png" alt="" /></a>',
            buttonNextHTML:'<a href="javascript:void(0)" class="next"><img src="/engines/commons/images/next.png" alt="" /></a>'
        });

        function onAfter(curr, next, opts) {
            var index = opts.currSlide;
            $('.prev')[index == 0 ? 'hide' : 'show']();
            $('.next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
        }

	
	//$("#products .zoom").fancybox();
/*
        $(".fancy").fancybox({
            'padding' : '0',
            'overlayOpacity' : '0.9',
            'overlayColor' : '#000',
            'titlePosition' : 'inside',
            'onStart':function() {
                $("#fancybox-inner").css("padding", "0px");
            },
            'onClosed': function() {
                $("#fancybox-inner").css("padding", "80px");
            }
        });

        $(".fancyZoom").fancybox({
            'padding' : '80',
            'overlayOpacity' : '0.9',
            'overlayColor' : '#000',
            'titlePosition' : 'inside',
            'onStart':function() {
                $("#fancybox-inner").css("padding", "80px");
                $("#fancybox-inner").css("top", "0px");
                $("#fancybox-inner").css("left", "0px");
            },
            'onClosed': function() {
                $("#fancybox-inner").css("padding", "0px");
            }
        });

        $(".fancyFrame700").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'autoScale'     	: false,
		'type'			: 'iframe',
		'width'			: 720,
		'height'		: 600,
		'scrolling'   		: 'auto',
                'overlayOpacity'        : '0.7',
                'overlayOpacity'        : '0.9',
                'overlayColor'          : '#000',
                'onComplete':function() {
                    $("#fancybox-frame").parent().css("padding", "0px");
                },
                'onCleanup': function() {
                    $("#fancybox-frame").parent().css("padding", "80px");
                }

	});
*/
        
        $(".fancy").fancybox({
            'padding' : '0',
            'overlayOpacity' : '0.9',
            'overlayColor' : '#000',
            'titlePosition' : 'inside'
        });

        $(".fancyZoom").fancybox({
            'padding' : '80',
            'overlayOpacity' : '0.9',
            'overlayColor' : '#000',
            'titlePosition' : 'inside'
        });

        $(".fancyFrame700").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'autoScale'     	: false,
		'type'			: 'iframe',
		'width'			: 720,
		'height'		: 600,
		'scrolling'   		: 'auto',
                'overlayOpacity'        : '0.7',
                'overlayOpacity'        : '0.9',
                'overlayColor'          : '#000'

	});


        /*
	//vedi http://orkans-tmp.22web.net/star_rating/ per la documentazione
	$("#ratings").children().not("select").hide();

	$("#ratings").stars({
		
		inputType: "select",
		cancelShow: false,
		callback: function(ui, type, value){
			$.post("product-rating.php", {rate: value}, function(data){
				//$("#ajax_response").html(data);
			});
		}
	
	});
	*/
       
	$( "#tabs" ).tabs();
	/*
	var config =  {
			chromeless: 0,
			playlistBuilder: function(videos){
				var list = $('<ul></ul>');
				$.each(videos, function(key, video){
					$('<li></li>')
						.data('video', this) // this is required
						.attr('title', this.title)
						.html('<a href="#"><img width="80" src="http://img.youtube.com/vi/' + this.id + '/default.jpg" alt="' + this.title + '" /></a><em>' + this.title + '</em><span></span>')
						.appendTo( list );
				});
				return {
					container: $('#playlist .scrollable'),
					items: list
						.appendTo('#playlist .scrollable')
						.addClass('jcarousel-skin-youtube-player')
						//.jcarousel()
						.find('li')
				};
			},
			playlistBuilderClickHandler: function(event){
				event.preventDefault();
			},
			playlist: {
				playlist: '984D9FC687957419'
			},
           onReady: function(){
				$('#playlist .scroll-wrapper').scrollgrab({
					speed: 		10,
					//debug:		true
				});
			}

		};

		$('.youtube-player').player(config);
*/
		$('#facebook-board .scroll-wrapper').scrollgrab({
			speed: 		10
			//debug:		true
		});

                /*
		$('#mediagallery #playlist .scrollable a.adv-link').click(function(event){
			
			$.get( 'adv.php', {id: $(this).attr('rel')}, function(data){
				$('.adv-player').html(data);
			});

			
		});
		
		$('#playlist .scroll-wrapper').scrollgrab({
			speed: 		10
		});
		$('#mediagallery #playlist .scrollable a.adv-link').eq(0).trigger('click');
		*/

               /* menu principale */
               var hoverIntentConfig = {
                     over: showSubmenu, // function = onMouseOver callback (REQUIRED)
                     timeout: 200, // number = milliseconds delay before onMouseOut
                     out: hideSubmenu // function = onMouseOut callback (REQUIRED)
                };

                function showSubmenu(){
                    $(this).find('ul').show();
                }

                function hideSubmenu(){
                    $(this).find('ul').hide();
                }

                $("#header #menu ul li").hoverIntent( hoverIntentConfig );

                /* fine menu principale */

                /* menu laterale */

/*
                $("#left-col #accordion > ul > li > a").click(function(){

                    if(false == $(this).parent().find("ul").is(':visible')) {
                        $('#left-col #accordion ul > li > ul').slideUp(300);
                    }
                    $(this).parent().find("ul").show(300);

                    if(($(this).parent().find("ul")).length > 0)
                        return false;
                    else
                        return true;
                    
                });

                //$('#left-col #accordion ul > li > ul:eq(0)').show();
*/

                /* fine menu laterale */



                $.fn.cycle.defaults = {
                            fx:             'fade', // name of transition effect (or comma separated names, ex: fade,scrollUp,shuffle) ,scrollUp,scrollHorz,scrollVert,turnUp
                            timeout:         4000,  // milliseconds between slide transitions (0 to disable auto advance)
                            timeoutFn:       null,  // callback for determining per-slide timeout value:  function(currSlideElement, nextSlideElement, options, forwardFlag)
                            continuous:      0,     // true to start next transition immediately after current one completes
                            speed:           1000,  // speed of the transition (any valid fx speed value)
                            speedIn:         null,  // speed of the 'in' transition
                            speedOut:        null,  // speed of the 'out' transition
                            next:            null,  // selector for element to use as click trigger for next slide
                            prev:            null,  // selector for element to use as click trigger for previous slide
                            prevNextClick:   null,  // callback fn for prev/next clicks:    function(isNext, zeroBasedSlideIndex, slideElement)
                            prevNextEvent:  'click.cycle',// event which drives the manual transition to the previous or next slide
                            pager:          '#nav',  // selector for element to use as pager container
                            pagerClick:      null,  // callback fn for pager clicks:    function(zeroBasedSlideIndex, slideElement)
                            pagerEvent:     'click.cycle', // name of event which drives the pager navigation
                            allowPagerClickBubble: false,  // allows or prevents click event on pager anchors from bubbling
                            pagerAnchorBuilder: null, // callback fn for building anchor links:  function(index, DOMelement)
                            before:          null,  // transition callback (scope set to element to be shown):     function(currSlideElement, nextSlideElement, options, forwardFlag)
                            after:           null,  // transition callback (scope set to element that was shown):  function(currSlideElement, nextSlideElement, options, forwardFlag)
                            end:             null,  // callback invoked when the slideshow terminates (use with autostop or nowrap options): function(options)
                            easing:          null,  // easing method for both in and out transitions
                            easeIn:          null,  // easing for "in" transition
                            easeOut:         null,  // easing for "out" transition
                            shuffle:         null,  // coords for shuffle animation, ex: { top:15, left: 200 }
                            animIn:          null,  // properties that define how the slide animates in
                            animOut:         null,  // properties that define how the slide animates out
                            cssBefore:       null,  // properties that define the initial state of the slide before transitioning in
                            cssAfter:        null,  // properties that defined the state of the slide after transitioning out
                            fxFn:            null,  // function used to control the transition: function(currSlideElement, nextSlideElement, options, afterCalback, forwardFlag)
                            height:         'auto', // container height
                            startingSlide:   0,     // zero-based index of the first slide to be displayed
                            sync:            1,     // true if in/out transitions should occur simultaneously
                            random:          0,     // true for random, false for sequence (not applicable to shuffle fx)
                            fit:             0,     // force slides to fit container
                            containerResize: 1,     // resize container to fit largest slide
                            pause:           0,     // true to enable "pause on hover"
                            pauseOnPagerHover: 0,   // true to pause when hovering over pager link
                            autostop:        0,     // true to end slideshow after X transitions (where X == slide count)
                            autostopCount:   0,     // number of transitions (optionally used with autostop to define X)
                            delay:           0,     // additional delay (in ms) for first transition (hint: can be negative)
                            slideExpr:       null,  // expression for selecting slides (if something other than all children is required)
                            cleartype:       !$.support.opacity,  // true if clearType corrections should be applied (for IE)
                            cleartypeNoBg:   false, // set to true to disable extra cleartype fixing (leave false to force background color setting on slides)
                            nowrap:          0,     // true to prevent slideshow from wrapping
                            fastOnEvent:     0,     // force fast transitions when triggered manually (via pager or prev/next); value == time in ms
                            randomizeEffects:1,     // valid when multiple effects are used; true to make the effect sequence random
                            rev:             0,     // causes animations to transition in reverse
                            manualTrump:     true,  // causes manual transition to stop an active transition instead of being ignored
                            requeueOnImageNotLoaded: true, // requeue the slideshow if any image slides are not yet loaded
                            requeueTimeout:  250,   // ms delay for requeue
                            activePagerClass: 'activeSlide', // class name used for the active pager link
                            updateActivePagerLink: null // callback fn invoked to update the active pager link (adds/removes activePagerClass style)
                        };

                        $('.cycleBanner').cycle();
                        
                        
                        $('#stato').live('change', function(){
                        	//alert($('#stato option:selected').text());
                        	if( $('#stato option:selected').text() == 'Italia'){
                        		$('#provincia td').css({visibility:'visible'});
                        	}else{
                        		$('#provincia td').css({visibility:'hidden'});
                        		$('#provincia option').eq(0).attr('selected', 'selected');
                        	}
                        });
                        
                        var urlParams = {};
                           var e,
                                a = /\+/g,  // Regex for replacing addition symbol with a space
                                r = /([^&=]+)=?([^&]*)/g,
                                d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
                                q = window.location.search.substring(1);

                            while (e = r.exec(q))
                               urlParams[d(e[1])] = d(e[2]);
                        
                        
                        if(urlParams['msg'] == 'ok'){
                        	$('#textmsg').css({display:'block'});
                        }                        
                        //alert(urlParams['msg']);

});


$(window).load(function(){
	$("#gallery img").each(function(){
            //alert($(this).css({width:$(this).width()}));
		$(this).css({width:$(this).width()});
	});

	$("#gallery").smoothDivScroll({
		scrollStep: 3,
		scrollInterval: 8,
		mouseDownSpeedBooster:	3,
		visibleHotSpots: "always",
		hotSpotsVisibleTime: 1000
	});$('.scrollableArea').width(2000);

});

