	Site = {}

var flashvars = {};
var params = {};
var attributes = {};
params.wmode = 'transparent';

Site.header = function () {

	swfobject.embedSWF('/swf/content_nubes.swf', 'nubes', '1920', '175', '9.0.0', false, flashvars, params, attributes);
	swfobject.embedSWF('/swf/player.swf', 'player', '8', '8', '9.0.0', false, flashvars, params, attributes);


	$('div#header a[href=/]').click(function () {

		$.ajax({
			url: '/?' + Math.random(),
			beforeSend: function () {
				$('div#content div.wrap:first').fadeOut('slow');
			},
			success: function (html) {
			
				$('div#content').html(html);
				$('div#content div.wrap:first').fadeIn('slow');
				$('div#header li.selected').removeClass('selected');
				$('div#header a[href=/]').parent().addClass('selected');
				$(window).trigger('resize');
				Site.pages();
				Site.navigation();
				pageTracker._trackPageview('/');
				
			}
		}); 
		
		return false;
	
	});
	$('div#header a[href=/pages/linea-verde]').click(function () {

		$.ajax({
			url: '/pages/linea-verde?' + Math.random(),
			beforeSend: function () {
				$('div#content div.wrap:first').fadeOut('slow');
			},
			success: function (html) {
			
				$('div#content').html(html);
				$('div#content div.wrap:first').fadeIn('slow');
				$('div#header li.selected').removeClass('selected');
				$('div#header a[href=/pages/linea-verde]').parent().addClass('selected');
				$(window).trigger('resize');
				Site.pages();
				Site.linea();
				Site.navigation();
				pageTracker._trackPageview('/linea-verde');
				
			}
		}); 
		
		return false;
	
	});
	$('div#header a[href=/tips]').click(function () {
	
		$.ajax({
			url: '/tips?' + Math.random(),
			beforeSend: function () {
				$('div#content div.wrap:first').fadeOut('slow');
			},
			success: function (html) {
			
				$('div#content').html(html);
				$('div#content div.wrap:first').fadeIn('slow');
				$('div#header li.selected').removeClass('selected');
				$('div#header a[href=/tips]').parent().addClass('selected');
				$(window).trigger('resize');
				Site.tips();
				Site.navigation();
				pageTracker._trackPageview('/tips');
			
			}
		});
		
		return false;
	
	});
	$('div#header a[href=/galleries]').click(function () {
	
		$.ajax({
			url: '/galleries?' + Math.random(),
			beforeSend: function () {
				$('div#content div.wrap:first').fadeOut('slow');
			},
			success: function (html) {
			
				$('div#content').html(html);
				$('div#content div.wrap:first').fadeIn('slow');
				$('div#header li.selected').removeClass('selected');
				$('div#header a[href=/galleries]').parent().addClass('selected');
				$(window).trigger('resize');
				Site.galleries();
				Site.navigation();
				pageTracker._trackPageview('/galeries');
			
			}
		});
		
		return false;
	
	});


	$('div#header a.facebook_btn').click(function () {
		
		$('div.twitter_widget a.close_btn').trigger('click');
		
		var widget = $('div.facebook_widget');
		widget.css('top', -widget.height());
		widget.animate({ top: 10 }, 2000).show();
	
		return false;
		
	});
	$('div#header a.twitter_btn').click(function () {
		
		var widget = $('div.twitter_widget');
		
		$('div.facebook_widget a.close_btn').trigger('click');
		
		widget.find('.twtr-join-conv').html('Siguenos');
		widget.css('top', -widget.height());
		widget.animate({ top: 100 }, 2000).show();
	
		return false;
		
	});


	$('div#networks a.close_btn').click(function () {
	
		var t = $(this);
		t.parent().animate({ top: -t.parent().height() }).hide('slow');
	
	});

}

Site.footer = function () {

	$(window).resize(function () {
	
		var w = $(window);
		var content = $('div#content div.wrap > div');
		var header = $('div#header');
		var footer = $('div#footer');
				
		if (content.outerHeight() >= (w.height() - (header.outerHeight() + footer.outerHeight()))) {

			footer.css('bottom', 'auto');
			$('div.pages.home').each(function () {
				var t = $(this);
				
				t.css('bottom', 'auto');
				t.css('top', '50%');
				t.css('margin-top', -215);
				
			});
	
		} else {
		
			$('div#content, div#content div.wrap').height(w.height() - (header.outerHeight() + footer.outerHeight()));

			$('div.pages.home').each(function () {
				var t = $(this);
				
				t.css('bottom', '15px');
				t.css('top', 'auto');
				t.css('margin-top', 0);
				
			});
		
		}
						
	});

	$(window).trigger('resize');

}

Site.tips = function () {

	var like = $('div.tips.index a.like_btn');
	
	like.click(function () {
	
		var t = $(this);
		var id = t.attr('rel').replace('ID', '');
		
		$.ajax({
			
			url: '/tips/vote',
			type: 'POST',
			data: '&data[Tip][id]=' + id,
			success: function (html) {
			
				t.fadeOut();
				t.parent().find('span').html(html);
			
			}
			
		})
		
		return false;
	
	});

	$('div.tips.index div.list').jCarouselLite({
		
		btnNext: 'div.tips.index a.next_btn',
		btnPrev: 'div.tips.index a.prev_btn',
		circular: false,
		visible: 6,
		scroll: 1,
		vertical: true
		
	});
	
	$('div.tips.index a.prev_btn').addClass('disabled');
	
}

Site.galleries = function () {

	$('div.galleries.index div.gallery.img a').fancybox({
	
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
		
	});

	$('div.galleries.index div.gallery.video a').fancybox({
	
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'type'			:	'swf'
		
	});
	
}

function lightbox(id) {
	var a = $('a#lightbox');
	
	$('a#lightbox').fancybox({
	
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'type'			:	'swf'
		
	});
	
	a.attr('href', id);
	a.trigger('click');
}

function lightbox_html(id) {
	var a = $('a#lightbox');
	
	$('a#lightbox').fancybox({
	
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
		
	});
	
	a.attr('href', id);
	a.trigger('click');
}

Site.pages = function () {

	swfobject.embedSWF('/swf/pages_home_vista360.swf', 'vista360', '550', '400', '9.0.0', false, flashvars, params, attributes);
	swfobject.embedSWF('/swf/home2011.swf', 'home2011', '960', '550', '9.0.0', false, flashvars, params, attributes);

	swfobject.embedSWF('/swf/layer.swf', 'layer', '500', '450', '9.0.0', false, flashvars, params, attributes);

	$('div.pages.home div.sumate div.item div.share').hide();
		
	$('div.pages.home div.sumate div.item').hover(function () {

		var t = $(this).find('div.share');
		t.fadeIn('slow');
 
	}, function () {

		var t = $(this).find('div.share');
		t.fadeOut('slow');

	});

	$('div.galleries div.item.img a').fancybox({
	
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'titlePosition'  : 'inside',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<a class ="facebook_btn" name="fb_share" type="icon_link" href="http://www.facebook.com/sharer.php?u=http://www.flickr.com&t=Logramos+la+Meta"> </a>' +
		    '<a href="http://www.twitter.com/home?statusEstoy visitando LG" class="twitter_btn" target="_blank">Twitter</a>'
		    ;
		}
		
	})

	$('div.galleries div.item.videos a').fancybox({
	
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'type'			:	'swf',
		'titlePosition'  : 'inside',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<a class ="facebook_btn" name="fb_share" type="icon_link" href="http://www.facebook.com/sharer.php?u=http://www.flickr.com&t=Logramos+la+Meta"> </a>' +
		    '<a href="http://www.twitter.com/home?statusEstoy visitando LG" class="twitter_btn" target="_blank">Twitter</a>'
		    ;
		}
		
	});
	
	$(window).resize(function () {
		var a = $('div.lightbox');
		var b = $('div.sidebar').offset();
		a.css('position', 'absolute');
		a.css('top', b.top - 59);
		a.css('left', b.left);
	});
	$(window).trigger('resize');
	
	$('div.lightbox').append('<a href="#" class="close_btn"></a>');

				$('div.lightbox').click(function () {
					$('div#header a[href=/galleries]').trigger('click');
				});
	
	$('a.close_btn').click(function () {
		$('div.lightbox').fadeOut();
	});
	
}

function hide_layer() {
	$("#layer").hide();
}


Site.navigation = function () {

	$('div#content div.wrap:first').show();

	$('div#content a[href=/]').bind('click', function () {
	
		$.ajax({
			url: '/?' + Math.random(),
			beforeSend: function () {
				$('div#content div.wrap:first').fadeOut('slow');
			},
			success: function (html) {
			
				$('div#content').html(html);
				$('div#content div.wrap:first').fadeIn('slow');
				$('div#header li.selected').removeClass('selected');
				$('div#header a[href=/]').parent().addClass('selected');
				$(window).trigger('resize');
				Site.pages();
				Site.navigation();
				pageTracker._trackPageview('/home');
			
			}
		});
		
		return false;
	
	});
	$('div#content a[href=/pages/linea-verde]').bind('click', function () {
	
		$.ajax({
			url: '/pages/linea-verde?' + Math.random(),
			beforeSend: function () {
				$('div#content div.wrap:first').fadeOut('slow');
			},
			success: function (html) {
			
				$('div#content').html(html);
				$('div#content div.wrap:first').fadeIn('slow');
				$('div#header li.selected').removeClass('selected');
				$('div#header a[href=/pages/linea-verde]').parent().addClass('selected');
				$(window).trigger('resize');
				Site.pages();
				Site.linea();
				Site.navigation();
				pageTracker._trackPageview('/linea-verde');
			
			}
		});
		
		return false;
	
	});
	$('div#content a[href=/tips]').click(function () {
	
		$.ajax({
			url: '/tips?' + Math.random(),
			beforeSend: function () {
				$('div#content div.wrap:first').fadeOut('slow');
			},
			success: function (html) {
			
				$('div#content').html(html);
				$('div#content div.wrap:first').fadeIn('slow');
				$('div#header li.selected').removeClass('selected');
				$('div#header a[href=/tips]').parent().addClass('selected');
				$(window).trigger('resize');
				Site.tips();
				Site.navigation();
				pageTracker._trackPageview('/tips');
			
			}
		});
		
		return false;
	
	});
	$('div#content a[href=/galleries]').click(function () {
	
		$.ajax({
			url: '/galleries?' + Math.random(),
			beforeSend: function () {
				$('div#content div.wrap:first').fadeOut('slow');
			},
			success: function (html) {
			
				$('div#content').html(html);
				$('div#content div.wrap:first').fadeIn('slow');
				$('div#header li.selected').removeClass('selected');
				$('div#header a[href=/galleries]').parent().addClass('selected');
				$(window).trigger('resize');
				Site.galleries();
				Site.navigation();
				pageTracker._trackPageview('/galleries');
			
			}
		});
		
		return false;
	
	});
	
	$('div.sidebar div.tips_btn a').click(function () {
	
		$.ajax({
			url: '/tips?' + Math.random(),
			beforeSend: function () {
				$('div#content div.wrap:first').fadeOut('slow');
			},
			success: function (html) {
			
				$('div#content').html(html);
				$('div#content div.wrap:first').fadeIn('slow');
				$('div#header li.selected').removeClass('selected');
				$('div#header a[href=/tips]').parent().addClass('selected');
				$(window).trigger('resize');
				Site.tips();
				Site.navigation();
				pageTracker._trackPageview('/tips');
			
			}
		});
		
		return false;
	
	});
	$('div.sidebar div.galleries_btn a').click(function () {
	
		$.ajax({
			url: '/galleries?' + Math.random(),
			beforeSend: function () {
				$('div#content div.wrap:first').fadeOut('slow');
			},
			success: function (html) {
			
				$('div#content').html(html);
				$('div#content div.wrap:first').fadeIn('slow');
				$('div#header li.selected').removeClass('selected');
				$('div#header a[href=/galleries]').parent().addClass('selected');
				$(window).trigger('resize');
				Site.galleries();
				Site.navigation();
				pageTracker._trackPageview('/galleries');
			
			}
		});
		
		return false;
	
	});
	
}

Site.preloader = function () {

	QueryLoader.selectorPreload = "body";
	QueryLoader.init();

}

Site.linea = function () {
	swfobject.embedSWF('/swf/pages_linea.swf', 'linea', '729', '376', '9.0.0', false, flashvars, params, attributes);
}

Site.go = function (id) {
	alert(id);
}

$(document).ready(function () {

	if ((u != 'Users') && (u != 'Causas')) Site.preloader();
	Site.header();
	Site.footer();
	Site.navigation();

	if (typeof $('div.tips.index')[0] != 'undefined') Site.tips();
	if (typeof $('div.pages.home')[0] != 'undefined') Site.pages();
	if (typeof $('div.pages.linea')[0] != 'undefined') Site.linea();
	if (typeof $('div.galleries.index')[0] != 'undefined') Site.galleries();

	$('div#content div.wrap:first').show();

	$('#nubes').show();

	$(window).trigger('resize');
	
	$('div.lightbox').show();
	
});
