$(document).ready(function() {
	$('.bgSamurai').animate( {"opacity":1},200 , function() {
		$('.wrapper_header').animate( {"opacity":1},200 , function() {
			$('#supersized').animate( {"opacity":1},800 );
		});
	});
	
	
});

$(document).ready(function() {
	
	/*Cufon*/
	Cufon.replace('.main_nav li a', { fontFamily: 'Optimer', fontWeight: 'regular'});
	Cufon.replace('h3', { fontFamily: 'FutenaExpert', fontWeight: 'regular' });
	

	
	$(function()
	{
		$('.holderScroll').jScrollPane();
	});
	/*main_nav*/
	$(function(){
		$(".main_nav li:eq(0)").addClass("nav_line");
		$(".main_nav li:eq(1)").addClass("nav_line");
		$(".main_nav li:eq(2)").addClass("nav_line");
		$(".lang_nav li:eq(0)").addClass("nav_line2");
	});
	
	$(function(){
		$('.main_nav li a').animate({"opacity":0.8},100);
		$('.main_nav li').hover(function(){
			$(this).children('a').stop().animate({"opacity":1},1000);
			$(this).children('.main_nav span.navhover').stop().animate({"opacity":1},1000)
		}, function(){
			$(this).children('a').stop().animate({"opacity":0.8}, 500);	
			$(this).children('.main_nav span.navhover').stop().animate({"opacity":0},500)
		});
	});
	
	/*lang_nav*/
	$(function(){
		$('.lang_nav li a').hover(function(){
			$(this).animate({ color: '#4F4F4F' }, {queue: false, duration: 500});
		}, function(){
			$(this).animate({ color: '#9D9D9D' }, {queue: false, duration: 500});
		});	
	});
	/*nav_social*/
	$('.fb_ico').animate({"opacity":0.4},100);
	$('.fb_ico').hover(function(){
        $(this).stop().animate({"opacity":1},1000);
		}, function(){
		$(this).stop().animate({"opacity":0.4},1000);
    });
	
	$('.tw_ico').animate({"opacity":0.4},100);
	$('.tw_ico').hover(function(){
        $(this).stop().animate({"opacity":1},1000);
		}, function(){
		$(this).stop().animate({"opacity":0.4},1000);
    });
	$('.copy').animate({"opacity":0.4},100);
	
	
	/***Flechas Video Nav***/
	$('.prev_proy').animate({"opacity":0.2},1000);
	$('.prev_proy').hover(function(){
        $(this).stop().animate({"opacity":0.6},1000);
		
		}, function(){
		$(this).stop().animate({"opacity":0.2},500);
		
    });
	$('.next_proy').animate({"opacity":0.2},1000);
	$('.next_proy').hover(function(){
        $(this).stop().animate({"opacity":0.6},1000);
		}, function(){
		$(this).stop().animate({"opacity":0.2},500);
    });
	$('.jspDrag').animate({"opacity":0.3},1000);
	$('.jspDrag').hover(function(){
        $(this).stop().animate({"opacity":1},1000);
		}, function(){
		$(this).stop().animate({"opacity":0.3},1000);
    });
		    
	/*slide_home*/	
	 $('div.slidehome_id')
	.cycle({
		fx: 'fade',
		speed:    300, 
		timeout:  800
	})
	.cycle('pause')
	.mouseover(function(){
	  $(this).cycle('resume');
	  $(this).stop().animate({"opacity":1}, 1000);	
	})
	.mouseout(function(){
	  $(this).cycle('pause');
	   $(this).stop().animate({"opacity":0.5}, 1000);	
	});

	
	
	/*Alineación Vertical*/
	(function ($) {
		$.fn.vAlign = function() {
			return this.each(function(i){
			var h = $(this).height();
			var oh = $(this).outerHeight();
			var mt = (h + (oh - h)) / 2;	
			$(this).css("margin-top", "-" + mt + "px");	
			$(this).css("top", "62%");
			$(this).css("position", "fixed");		
			});	
		};
	})(jQuery);
	$('.slide_home').vAlign();
	$('.carousel_directores').vAlign();
	$('.grid_projects').vAlign();
	$('.about').vAlign();
	$('.contacto').vAlign();
	$('.director_detalle').vAlign();
	/*Mapa Visible*/
	$(function() {
			
			
			$('.linkmap').click(function() {
			  $('.map').slideDown('fast', function() { 
			  });
			});
			
			$('.close_map a').click(function() {
			  $('.map').slideUp('fast', function() { 
			  });
			});
	});
	
	/***Carousel Directores***/
	$(function(){
		$(".dirimgclass").animate({"opacity":0.6});

		
		$(".dirimgclass").hover(function()
		{
			var vid_name = this.id;
			aidname = explode("_",vid_name);
			var vid_num = aidname[1];
				
			$(this).stop().animate({"opacity":1}); 
			$("#dirname_"+vid_num).stop().animate({"opacity":1}); 
			/*EL stop detiene la animación cuando se pasa varias veces seguidas por encima*/
		}, function()
		{
			var vid_name = this.id;
			aidname = explode("_",vid_name);
			var vid_num = aidname[1];
			
			$(this).stop().animate({"opacity":0.6});
			$("#dirname_"+vid_num).stop().animate({"opacity":0.6}); 	
		});
		
	});
	
	/***Proyectos Directores***/
	$(function(){
		$("ul.proy_list .proy_item .pic_img img").animate({"opacity":0.6});
			
		$("ul.proy_list .proy_item .pic_img img").hover(function()
		{
			$(this).stop().animate({"opacity":1}); 
		}, function()
		{
			$(this).stop().animate({"opacity":0.6});	
		});		
	});
	
	/****/
	$(function(){
		$(".dirnameclass").animate({"opacity":0.6});
			
			$(".dirnameclass").hover(function()
			{
				var vid_name = this.id;
				aidname = explode("_",vid_name);
				var vid_num = aidname[1];
				
				$(this).stop().animate({"opacity":1}); 
				$("#dirimg_"+vid_num).stop().animate({"opacity":1});
			}, function()
			{
				var vid_name = this.id;
				aidname = explode("_",vid_name);
				var vid_num = aidname[1];
				
				$(this).stop().animate({"opacity":0.6});	
				$("#dirimg_"+vid_num).stop().animate({"opacity":0.6});
			});		
	});
	
	
});

function explode (delimiter, string, limit) {
    // http://kevin.vanzonneveld.net
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
    var emptyArray = {
        0: ''
    };

    // third argument is not required
    if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined') {
        return null;
    }

    if (delimiter === '' || delimiter === false || delimiter === null) {
        return false;
    }

    if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
        return emptyArray;
    }

    if (delimiter === true) {
        delimiter = '1';
    }

    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

function str_replace (search, replace, subject, count) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order
    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
    var i = 0,
        j = 0,
        temp = '',
        repl = '',
        sl = 0,
        fl = 0,
        f = [].concat(search),
        r = [].concat(replace),
        s = subject,
        ra = Object.prototype.toString.call(r) === '[object Array]',
        sa = Object.prototype.toString.call(s) === '[object Array]';
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i = 0, sl = s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j = 0, fl = f.length; j < fl; j++) {
            temp = s[i] + '';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length - s[i].length) / f[j].length;
            }
        }
    }
    return sa ? s : s[0];
}


