var ipod_activo = 0;

$(document).ready(function(){
	resize();
	$('#home_section').load('?sec=home', {ajax: 1}, init_site);
	$('#about_section').load('?sec=about', {ajax: 1}, init_site);
	$('#howdo_section').load('?sec=how_do_we_do_it', {ajax: 1}, init_site);
	$('#projects_section').load('?sec=projects', {ajax: 1}, init_site);
	$('#team_section').load('?sec=team', {ajax: 1}, init_site);
	$('#contact_section').load('?sec=contact', {ajax: 1}, init_site);
	
	var fast_menu_on = false;
	$('#fast_menu').hover(function(){
		if(!fast_menu_on){
			$('#fast_menu ul').slideDown(500);
			fast_menu_on = true;
		}
	}, function(){
		if(fast_menu_on){
			$('#fast_menu ul').slideUp(500);
			fast_menu_on = false;
		}
	});
});

	
function init_site(){
	$('.goto_home').click(function(event){
		event.preventDefault();
		$('html,body').animate({scrollLeft: 0}, 400);
	});
	
	$('.goto_about').click(function(event){
		event.preventDefault();
		$('html,body').animate({scrollLeft: 1000}, 400);
	});
		
	$('.goto_howdo').click(function(event){
		event.preventDefault();
		$('html,body').animate({scrollLeft: 2000}, 400);
	});
	
	$('.goto_projects').click(function(event){
		event.preventDefault();
		$('html,body').animate({scrollLeft: 3000}, 400);
	});
	
	$('.goto_contact').click(function(event){
		event.preventDefault();
		$('html,body').animate({scrollLeft: 4000}, 400);
	});
	
	$('.up_team').click(function(event){
		event.preventDefault();
		$('#team_section').slideDown(400);
		$('#about_section').hide();
	});
	
	$('.down_team').click(function(event){
		event.preventDefault();
		$('#about_section').slideDown(400);
		$('#team_section').hide();
	});
	
	$('.dinpag').click(function(event){
		event.preventDefault();
		var href = $(this).attr('href');
		var rel  = $(this).attr('rel');
		$('#' + rel + '_section').load(href, {ajax: 1}, init_site);
	});

    $('.button').mouseenter(function(event){
            var image = $(this).attr('src');
            if(image.search('_over.png') == -1)
            {
                var newimage = image.replace('.png', '_over.png');
                $(this).attr('src', newimage);
            }
        });

    $('.button').mouseleave( function(){
            var image = $(this).attr('src');
            var newimage = image.replace('_over.png', '.png');
            $(this).attr('src', newimage);
        });
    
    $('.seccion_commercial').click(function(event){
    	event.preventDefault();
    	$('#projects_section').load('?sec=projects&seccion=seccion1', {ajax: 1}, init_site);
    });
    
    $('.seccion_furniture').click(function(event){
    	event.preventDefault();
    	$('#projects_section').load('?sec=projects&seccion=seccion2', {ajax: 1}, init_site);
    });
    
    $('.seccion_residential').click(function(event){
    	event.preventDefault();
    	$('#projects_section').load('?sec=projects&seccion=seccion3', {ajax: 1}, init_site);
    });
    
    $('.seccion_shows').click(function(event){
    	event.preventDefault();
    	$('#projects_section').load('?sec=projects&seccion=seccion4', {ajax: 1}, init_site);
    });
}

function resize(){
	var size = $(window).width();
	var extra = 0;
	
	if(size > 1000)
	{
		extra = (size - 1000)/2;
	}
	
	$('#home_section').css('margin-left', extra);
	$('#contact_section').css('padding-right', extra);
	$('#fast_menu').css('left', extra + 20);
	var width = 5000 + extra*2;
	$('#magic').width(width);
}

$(window).resize(resize);


