var paircount = 0;

/* If you want to desaturate after page loaded - use onload event
* of image.
*/
function initImage(obj){
	obj.onload = null;
	var $newthis = $(obj);
	if ($.browser.msie){
	  // You need this only if desaturate png with aplha channel
	  $newthis = $newthis.desaturateImgFix();
	}
	// class for easy switch between color/gray version
	$newthis.addClass("pair_" + ++paircount);
	var $cloned = $newthis.clone();
	// reset onload event on cloned object
	$cloned.get(0).onload = null;
	// add cloned after original image, we will switch between
	// original and cloned later
	$cloned.insertAfter($newthis).addClass("color").hide();
	// desaturate original
	$newthis.desaturate();
};

$(function(){

$('.xxx').data('desaturate', {'level':0.5});

$(".switched_images").bind("mouseenter mouseleave", function(event) {
	if (event.type == 'mouseenter')
	{
	  //$(".des:not(.color)", this).fadeOut(1000);
	  $(".des.color", this).fadeIn(200);
	}
	if (event.type == 'mouseleave')
	{
	  //$(".des:not(.color)", this).fadeIn(1000);
	  $(".des.color", this).fadeOut(200);
	}
  });
});

if(jQuery) (function($) { 
	$.extend($.fn, {
		hover_list : function(){
			$(this).hover(function(){
				$(this).find('div').fadeIn('fast');
			}, function(){
				$(this).find('div').fadeOut('fast');
			});
		},
		buttons_slider : function(){
			$(this).live({
				mouseenter : function(){
					var titles = $('#slider img:eq('+$(this).index()+')').attr('title').split('|');
					$('.nivo-controlNav').append('<div><span>'+titles[0]+'</span><span class="flechita"></span></div>');
					$('.nivo-controlNav div').css({
						'left' : ($(this).position().left + ($(this).outerWidth(true))/2) - ($('.nivo-controlNav div').outerWidth(true)/2) +'px', 
						'opacity' : 0,
						'top' : ($(this).position().top) +'px' 
					}).animate({
						opacity : 1,
						top : $(this).position().top - 28 + 'px'
					}, 150);
				},
				mouseleave:function() {
					$('.nivo-controlNav div').remove();
				}
			});
		},
		adjunto : function(){
			$(this).prev().change(function(){
				var file = $(this).val().split('\\');
				$('.file').html(file[file.length-1]);				  
			});
			$(this).click(function(){
				$(this).prev().click();	
			});
		},
		load_video : function(){
			$(this).each(function(){
				var video = $(this);
				
				id = video.attr('id', 'video'+Math.random());
				jwplayer(video.attr('id')).setup({
					'flashplayer': '../../wp-content/themes/morillas/js/player.swf',
					'file': video.attr('rel'),
					'backcolor': '111111',
					'frontcolor': 'cccccc',
					'lightcolor': '66cc00',
					'playlistsize': '200',
					'skin': 'http://www.longtailvideo.com/jw/upload/stylish.swf',
					'controlbar': 'bottom',
					'width': '460',
					'height': '349'
				});
			});
		},
		cliente_select : function(){
			$(this).change(function(){
				location.href = '?c='+$(this).val();
			});
		}		
    });
})(jQuery);

$(document).ready(function(){
	$('#list a').hover_list();	
	$('.nivo-controlNav a').buttons_slider();
	$('.adjuntar').adjunto();
	$('.comunity a').open({
	  width: 500,
	  height: 500,
	  top:  250, 
	  left: 250, 
	  scrollbars: true
	});
	$('.video').load_video(); 
	$('.clients_select').cliente_select();
	$('.subscribe a').open({
	  width: 600,
	  height: 950,
	  top:  250, 
	  left: 250, 
	  scrollbars: true
	});
});
