$(document).ready(function(){
/*-----------  INPUT VALUES ERASED ---------------*/
(function($){
	$.fn.clearDefault = function(){
		return this.each(function(){
			var default_value = $(this).val();
			$(this).focus(function(){
				if ($(this).val() == default_value) $(this).val("");
			    $(this).addClass('active-input');
			});
			$(this).blur(function(){
				if ($(this).val() == "") $(this).val(default_value);
			    $(this).removeClass('active-input');
			});
		});
	};
})(jQuery); // Usage: $('input.clear-default').clearDefault();

/*-----------  IMAGE PRELOAD ---------------*/
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery) // Usage: jQuery.preLoadImages("image1.gif", "/path/to/image2.png")

	var elems = $("#nav h2 a");
	for ( var n = 0; n < elems.length; n++ ) {
		jQuery.preLoadImages(elems[n].getAttribute( "rel" ));
	}
/*-----------  IMAGE PRELOAD END ---------------*/
	var docHeight = $(window).height();
	if(docHeight > 950){
		$("#projects .link_image").height(400);
		$("#projects .link_image").css({marginBottom: '45px'});
		$("#projects .link_image img").css({top:'0px'});
	} else if (docHeight > 900 ){
		$("#projects .link_image").height(350);
		$("#projects .link_image").css({marginBottom: '35px'});
		$("#projects .link_image img").css({top:'-25px'});
	}

/*************************************
  			CONTENT
 *************************************/
 /*-----------  HOME ---------------*/
 

	$("#nav h2").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});
	var originalTop = $(".home .link_image img").css("top");
	$(".home .link_image img").css("top", "0");
	$("#nav h2").children("a").hover(
		function () {
			var source = $(this).attr("rel");

			$(".home .link_image img").stop(false,true).fadeOut(150, function(){
				$(this).attr("src", source).fadeIn(150,function(){});
				if (source == "http://www.kotoc-produccions.com/wp-content/files_mf/1284462476DesafioChampions03.jpg"){
					$(this).css("top","0px");
				} else {
					$(this).css("top", originalTop);
				}
			});
		}, 
		function () {
		}
	);
	
	$("#nav h3").children("a").hover(
		function () {
			var source = $(this).attr("rel");
			$(".home .link_image img").stop(false,true).fadeOut(150, function(){
				$(this).attr("src", source).fadeIn(150);
			});
		}, 
		function () {
		}
	);
	
	
	$('#slide-cycle').cycle({ 
		fx: 'scrollLeft',
	});
	
    $(".project_title").hover(
      function () {
		$(this).css({ top: '-64px'});

      }, 
      function () {
        $(this).css({top: "-64px"});
      }
    );
	
///////////// LOGIN////  //////////////////////////////////	
    /*$('input#user_login').clearDefault();
    $('input#user_pass').clearDefault();*/
	
    $("#wp-submit").hover(
      function () {
		$(this).css({ backgroundPosition:"19px bottom"});

      }, 
      function () {
		$(this).css({ backgroundPosition:"19px 3px"});
      }
    );
	
	$("#login_form").submit(function()
	{
		var user_name     = $("#user_name").val();
		var user_password = $("#user_password").val();
		$.post("usercheck.php",{ user_name:user_name, user_password:user_password } ,function(data)
		{
			if ( data == 'YES' ) {
				$("#msgbox").removeClass().addClass('messagebox').text('Login OK').fadeIn(1000);
			}
			else {
				$("#msgbox").removeClass().addClass('messagebox').text('Login Incorrect').fadeIn(1000);
			}
		});
		return false;
	});
///////////// LANGUAGES ///////////////////////////////////////
    $("#lang ul li").hover(
      function () {
		$(this).children("a").animate({ color: '#464646'}, 100 );
      }, 
      function () {
        $(this).children("a").animate({color: "#b0b0b0"}, 100);
      }
    );	
	
///////////// thumb Projects  //////////////////////////////////				   
    $(".link_image-thumb").hover(
      function () {
        $(this).children(".project_title-thumb").fadeIn(100);
      }, 
      function () {
        $(this).children(".project_title-thumb").fadeOut(100);
      }
    );
	$(".link_image-thumb").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});

///////////// PROJECT LISTS  /////////////////////////
$(".project-list-img").hover(
	function (){
		$(this).siblings(".project-list-title").children("a").css({ background: '#ff0033', color: '#ffffff'});
		Cufon.replace('.project-list-title a', {fontFamily: 'Clan-Book',  hover: true});
	},
	function (){
		$(this).siblings(".project-list-title").children("a").css({ background: '#f8f8f8', color: '#616161'});
		Cufon.replace('.project-list-title a', {fontFamily: 'Clan-Book',  hover: true});
	}
							 
);

$(".project-list-title a").hover(
	function (){
		$(this).css({ background: '#ff0033', color: '#ffffff'});
		Cufon.replace('.project-list-title a', {fontFamily: 'Clan-Book',  hover: true});
	},
	function (){
		$(this).css({ background: '#f8f8f8', color: '#616161'});
		Cufon.replace('.project-list-title a', {fontFamily: 'Clan-Book',  hover: true});
	}
							 
);
///////////// SINGLE PROJECT  /////////////////////////

	$("#slideshow img").css({position: 'absolute'});
	$("#single-project p").css({width: '750', columnCount: '2'});
	
	var flashWidth = $(".flash").children("object").attr("width");
	var flashHeight = $(".flash").children("object").attr("height");
	$(".flash").css({width: flashWidth+'px', height: flashHeight+'px'});


///////////// PRIVATE PROJECT  /////////////////////////
	$(".private-web h2").appendTo(".menu");
	$(".private-page").appendTo(".content");
	$(".private-page").hide(0);
	$(".private-page:first-child").show(0);
	$(".private-web h2:first-child a").addClass("active-link")
	
	var navKids = $(".menu").children("h2");
	for (i = 0; i < navKids.length+1; i++){
		$(".menu h2:nth-child("+i+")").addClass('id'+i);
	}
	var contentKids = $(".content").children(".private-page");
	for (i = 0; i < navKids.length+1; i++){
		$(".private-page:nth-child("+i+")").addClass('id'+i);
	}
	
	$(".private-web h2").click(function (e){
		var actual = $(this).attr("class");
		$(".private-page").fadeOut(250);
		$(".private-web h2 a").removeClass("active-link");
		$(this).children("a").addClass("active-link");
		$(".content ."+actual).fadeIn(250);
		Cufon.refresh('.private-web h2 a', {fontFamily: 'Clan-Bold',  hover: true});
		
		return false;							  
	});
	
	$(".private-web .content a").click(function (e){
		var actual = $(this).parent().atrr("class");
		alert(actual);
		
		return false;							  
	});
	
    /*$('.comments textarea').clearDefault().corner("5px");*/
	$(".input-button").corner("5px");
	$("#private-login label").corner("2px left");
	$("#private-login input").corner("2px right");
	$("#private-submit input").corner("2px");

////////////// ABOUT  ///////////////////////////////
    $(".link_image").hover(
      function () {
        $(this).children(".member").fadeIn(100);
      }, 
      function () {
        $(this).children(".member").fadeOut(100);
      }
    );
    $("#kotokies ul li").hover(
      function () {
		$(this).children("a").animate({ opacity: '1'}, 100 );

      }, 
      function () {
        $(this).children("a").animate({ opacity: '0.4'}, 100 );
      }
    );	
////////////// CONTACTA //////////////////////////////////////////


   /* $('#contact form .input-small').clearDefault();
    $('#contact form .input-big').clearDefault();*/
	$("#contact-form input").corner("5px");
	$("#contact-form textarea").corner("5px");
	
	
////////////// JOBS //////////////////////////////////////////
    $("#jobs .select li").hover(
      function () {
		$(this).children("span").animate({ color: '#464646'}, 100 );

      }, 
      function () {
        $(this).children("span").animate({color: "#b0b0b0"}, 100);
      }
    );	
/////////////////////////////////////////////////////////////////
	$("#nav h2").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});
	
	$("#news ul li").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});
///////////////////////////////////////////////////////////////////

    $(".hover").hover(
      function () {
		$(this).children("a").animate({ color: '#464646'}, 100 );

      }, 
      function () {
        $(this).children("a").animate({color: "#b0b0b0"}, 100);
      }
    );	
	
    $("#news ul li").hover(
      function () {
		$(this).children("span").animate({ color: '#464646'}, 100 );
		$(this).children("p").animate({ color: '#464646'}, 100 );

      }, 
      function () {
        $(this).children("span").animate({color: "#b0b0b0"}, 100);
        $(this).children("p").animate({color: "#b0b0b0"}, 100);
      }
    );
	
////////////// FOOTER //////////////////////////////////////////

    $("#footer-outer").css({ backgroundColor: 'rgba(7,7,7,0.9)'});
	
	$("#footer h3").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});
	
    $("#footer-outer").hover(
      function () {
		$(this).stop(true, false).css({ backgroundColor: 'rgba(31,31,31,1)'}, 200 );
		$(this).stop(true, false).animate({ height: '56'}, 200 );
		$("#footer").children("h3").stop(true, false).animate({ paddingTop: '24'}, 200 );
		Cufon.refresh('#footer h3', {fontFamily: 'Clan-Medium',  hover: true});

      }, 
      function () {
		$(this).stop(true, false).css({ backgroundColor: 'rgba(7,7,7,0.9)'}, 300 );
		$(this).stop(true, false).animate({ height: '40'}, 300 );
		$("#footer").children("h3").stop(true, false).animate({ paddingTop: '15'}, 300 );
		Cufon.refresh('#footer h3', {fontFamily: 'Clan-Medium',  hover: true});
      }
    );	

	
    $("#footer-outer h3").hover(
      function () {
		$(this).stop(true, false).children("a").css({ color: "#E6E6E6"});
		Cufon.refresh('#footer h3', {fontFamily: 'Clan-Medium',  hover: true});

      }, 
      function () {
		$(this).stop(true, false).children("a").css({ color: "#737373"});
		Cufon.refresh('#footer h3', {fontFamily: 'Clan-Medium',  hover: true});
      }
    );	
	
////////////// NEWS //////////////////////////////////////////
	
    $(".page-news h2").hover(
      function () {
		$(this).children("a").animate({ color: '#ff0033'}, 100 );
      }, 
      function () {
        $(this).children("a").animate({color: "#464646"}, 100);
      }
    );
	
/*************************************
  			MISC
 *************************************/
/*----  IMG Captions ----*/
	/*var alt = $("img").attr('alt');
	var addCaption = '<span class="caption">'+alt+'</span>';
	$(".content img").after(addCaption);*/
	var aImgs = $(".content img");
	var i = 0;
	while (i < aImgs.length) {
    		aImgs[i].id = "imgCaption-"+i;
    		var alt = $("#imgCaption-"+i).attr("alt");
    		$("#imgCaption-"+i).after('<span class="caption">'+alt+'</span>');
    		i++;
	}
	
});

/*************************************
  			CUSTOM FUNCTIONS
 *************************************/	

