﻿$(document).ready(function(){

	/*-------------- MAIN MENU --------------*/
    if( uri != null ){
        $('.mainNav .nav > li').eq(uri).addClass('current');
    }
	$('.nav li').find('ul').addClass("subNav");
		
    $('.nav li').hover(function(){
        $(this).find('.subNav').stop(true, true).delay(200).show(300, 'easeOutBack');
    }, function(){
        $(this).find('.subNav').stop(true, true).hide(200);
    });
	
	$('.nav .subNav').find('li').removeClass("first");
	$('.nav .subNav').find('li').removeClass("last");
	
	/*-------------- TWITTER WIDGET --------------*/
    if( $('#twitter_widget').length > 0 ){
        $('#twitter_widget').twitterSearch({
            term        : 'carnaval_enc OR carnaval encarnaceno OR #CorsosEncarnacenos OR #Corsos2012',
            title       : 'Carnavales Encarnacenos Twitter',
            titleLink   : 'http://www.carnaval.com.py',
            //animOut   : { opacity: 0 },
            //avatar    : false,
            //anchors   : false,
            bird        : false,
            pause       : true,
            time        : false,
            timeout     : 8000
        });
    }
    //More info: http://jquery.malsup.com/twitter/

	if( $('.fancybox').length > 0 ){
        // Simple image gallery. Use default settings
        $('.fancybox').fancybox({
			aspectRatio : true,
            helpers : {
                title : { type : 'inside' }
            },
			afterClose : function(){
				$('#fancybox-loading').detach();
			}
        });
		
    }
        
    if ( $('.fancybox_map').length > 0 ) {
        $('.fancybox_map').click(function(){
            $('*[title]').poshytip('hide');
        }).fancybox({
            type: 'image',
            helpers : {
                title : { type : 'inside' }
            },
			afterClose : function(){
				$('#fancybox-loading').detach();
			}
			
        });
    }

	/*-------------- GALLERY --------------*/
    if( $('.gallery').length > 0 ){
        $('.gallery ul').cycle({
    		fx                  : 'scrollHorz',
            pause               : 1,
    		speed               : 300,
    		timeout             : false
    	});

        $('.galleryNavCarousell a').click(function(){
            var r = parseInt( $(this).attr('rel') );
            $('.gallery ul').cycle(r);

            $('.gallery iframe.visible').fadeOut(300, function(){
                $(this).removeClass('visible');
                $('.videoNav .active').removeClass('active');
            });
            return false;
        });
		
		$('.galleryNavCarousell a').each(function(){
			$(this).attr('rel',$(this).index())
			
		});
    };

    if($('.galleryNav').length > 0){
        $('.galleryNavCarousell').carouFredSel({
	        auto        : false,
            items       : 5,
            scroll      : 2,
            infinite    : true,
            circular    : true,
            prev        : ".galleryNav .prev",
	        next        : ".galleryNav .next"
    	});
    };

});//DOM ready end


$(window).load(function(){
    /*-------------- DYNAMIC BACKGROUND --------------*/
    if($('.dynamic').length > 0){
        $('.dynamic').cycle({
    		fx                  : 'fade',
            pager               : '.dlDotsNav',
    		speed               : 1000,
    		timeout             : 8000
    	});
    };

	/*-------------- DYNAMIC DATES --------------*/
    if($('.dynamic_dates').length > 0){
        $('.dynamic_dates #dl').cycle({
            fx                  : 'fade',
            //pager               : '.dlDotsNav',
    		speed               : 1000,
    		timeout             : 10000
        });
    };

    /*-------------- DYNAMIC NEWS --------------*/
    if($('.twitter_ticker').length > 0){
        $('.twitter_ticker ul').cycle({
    		fx                  : 'scrollHorz',
            //pager               : '.dlDotsNav',
    		speed               : 1000,
    		timeout             : 6000
    	});
    };

});
