/****************************************************************************************/
/*		Se van a traspasar todas las funciones.... aqui ;)							 	*/
/****************************************************************************************/
//Valores Generales

/////////////////////////////////////////////////////////////////////////////////
//Control con checbox

if(jQuery) (function($) { 
					 
	var default_values = new Array();
	
	//Con Objeto HTMl
	$.extend($.fn, {
		rotate_img : function(){	
			var path = this.find('.top').attr('src').split("f_home_"); //patt[0] is path :D 
			var top = this.find('.top');
			var bottom = this.find('.bottom');
			
			$('#slide_buttons a').click(function(){
				bottom.attr('src', path[0]+"f_home_"+$(this).text()+".jpg");
				
				$('#slide_buttons a').clear_class('active');
				$(this).addClass('active');
				
				top.fadeOut(1500, function(){
					top.attr('src',bottom.attr('src'));
					top.show();
					
				});
			});
			
			$('#slide_buttons a.active').rotate();
		},
		rotate : function(){
			if(this.is(':last-child')){
				$('#slide_buttons a:first').delay(4000).show('slow', function(){
					$(this).click();
					$('#slide_buttons a.active').rotate();
				});	
			}else{
				this.next().delay(4000).show('slow', function(){
					$(this).click();
					$('#slide_buttons a.active').rotate();
				});		
			}
		},
		clear_class : function (classname){
			this.each(function(){			   
				$(this).removeClass(classname);			   
			});				
		},
		map_efect : function(){
			$('#map_list_info').hide();
			$(this).find('area').each(function(){
				$(this).mouseenter(function(){	
					$('#office_map').append("<div class='info_map'>"+$("."+$(this).attr("id")).html()+"</div>");	
					$('.info_map').css('background-color', $("."+$(this).attr("id")).css('background-color'));
				}).mouseleave(function(){	
					$('#office_map').find(".info_map").remove();	
				}).show_form();
			});
		},
		show_form : function(){
			this.click(function(){
				$("body").append('<div id="bobble"></div>');
				$("body").append('<div id="form"></div>');
				$("#form").load("/wp-content/themes/sys/form_contact.php", {"email" :$("."+$(this).attr("id")).attr('title')}, function(){
					$('#form form').validate({
						rules: {
							company: {
								required: "#particular:unchecked"
							}
						},
						submitHandler: function() {
							var valores = $('#form :input').serialize();
							$.post("/wp-content/themes/sys/form_control.php", valores , function(){
								$('#form').html('<div class="close"></div><ul style="padding:20px; list-style:none"><li class="big"><h2>Formulario de contacto</h2></li><li><p>Muchas Gracias.</p></li></ul>');
							});	
							$('#form').html('<div class="close"></div><ul style="padding:20px; list-style:none"><li class="big"><h2>Formulario de contacto</h2></li><li><p>Muchas Gracias.</p></li></ul>');	
					   }
					});
					$("#bobble, .close").click(function(){
						$("#bobble").remove();	
						$('#form').remove();
					});
				});
				return false;
			});	
		},
		show_web20 : function(){
			$(this).hover(function(){
				$(this).find('ul:first').slideDown(400);
			},function(){
				$(this).find('ul:first').slideUp(400);
			});
		},
		show_buble : function(){
			$(this).mousemove(function(e){
				$(this).next().show();	
				if(window.pageYOffset){
					var offset = window.pageYOffset;	
				}else{
					var offset = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
				}
				
				if($(window).height()+offset-15 < (e.pageY+$(this).next().height())){
					$(this).next().css({"top" : e.pageY-$(this).next().height(), "left" : e.pageX+10});	
				}else{
					$(this).next().css({"top" : e.pageY, "left" : e.pageX+10});	
				}
			}).mouseout(function(){
				$(this).next().hide();
			});
		},
		show_video : function(){
			this.click(function(){
				$("body").append('<div id="bobble"></div>');
				$("#bobble").load("/wp-content/themes/sys/video.php?video="+$(this).attr('href'));
				$("#bobble").click(function(){
					$(this).remove();							
				});
				return false;
			});	
			
		}
		
	});

	//Sin Objeto HTML
	$.extend($, {
		get_img : function(){
			
		}
	});
})(jQuery);	


$(document).ready(function(){
	if($('#slide_img').size() > 0){
		$('#slide_img').rotate_img();
	}
	$('#office_map').map_efect();
	$('#web20').show_web20();
	$('.bubble span').show_buble();
	$('.videos').show_video();
	$('form').validate({
	  rules: {
		company: {
		  required: "#particular:unchecked"
		}
	  }
	});
});
