// JavaScript Document

$(document).ready(function() {
	
	Community.Init();
	
	$(".lightbox a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_rounded'});
	
	var $count = 0;
	
	$("ul.entry-list-container li").each(function()
	{
		$count++;
		if($count > 3)
		{
			$(this).find('div.block').css({ 'marginRight' : 0});
			$count = 0;
		}
	});
	
	var $count2 = 0;
	
	$("ul.work-list-container li").each(function()
	{
		$count2++;
		if($count2 > 3)
		{
			$(this).find('div.block').css({ 'marginRight' : 0});
			$count2 = 0;
		}
	});

	$('a[rel*=external]').click(function()
	{
		window.open(this.href);
		return false;
	});

	//----------------------------------------------------------------------------------
	// fancybox mime-types for ee-startpage containers
	//----------------------------------------------------------------------------------
	
	$("a.mime-image").fancybox({ 'hideOnContentClick': true });
	
	$("a.mime-link").fancybox( {
		'hideOnContentClick': true,
		'frameWidth': 800,
		'frameHeight': 600
	});
	
	$("a.mime-video").fancybox({ 'hideOnContentClick': true });
	
	//----------------------------------------------------------------------------------
	// qtip bubbles for href title tooltip
	//----------------------------------------------------------------------------------
	
	$('#content a[title]').each(function()
	{
		$(this).qtip({
			content: {
				prerender: true,
				text: '<img src="/files/images/bubble_logo.jpg" alt="' + $(this).text() + '" /><h3>Folge deinem Herzen ...</h3><p>' + $(this).attr('title') + '</p>'
			},
			position: {
				corner: {
					target: 'bottomMiddle',
					tooltip: 'topMiddle'
				},
				adjust: {
					screen: false
				}
			},
			show: { 
				when: 'mouseover', 
				solo: true,
				delay: 250,
				ready: false,
				effect: function(duration){
					this.css({ 'z-index': 9999, opacity:0, display:'block', 'marginTop': 10 });
					this.stop(true, false).animate({ height:200, 'marginTop': 0, opacity: 1 }, { duration: 250 });
				}
			},
			hide: {
				when: 'mouseleave',
				effect: function(duration)
				{
					this.css({ opacity: this.css('opacity') });
					this.stop(true, false).animate({ 'marginTop': 10, opacity: 0 },{ duration: 250, complete: function(){ $(this).css({ display: 'none' }); }});
				}
			},
			style: {
				tip: false,
				textAlign: 'center',
				border: {
					width: 5,
					radius: 5,
					color: '#DAF4FF'
				}
			}
		})
	})

	//----------------------------------------------------------------------------------
	// add target blank support for links with class external
	//----------------------------------------------------------------------------------
	
	$('#content a.external').attr('target', '_blank');
	
	//----------------------------------------------------------------------------------
	// cycle through fancybox work
	//----------------------------------------------------------------------------------
	
	$('div#content div.work-cycle-inner').cycle(
	{ 
		fx: 'scrollHorz',    
		delay: 0,
		easing: 'easeInOutExpo',
		speed: 1000,
		timeout: 0,
		requeueOnImageNotLoaded: false,
		next: 'div.work-cycle-nav a#next1',
		prev: 'div.work-cycle-nav a#prev1'
	});
	
	//----------------------------------------------------------------------------------
	// login button und login box
	//----------------------------------------------------------------------------------
	
	$('li.orange a.toggle').toggle(function(){
		$(this).parent().find('div.login-box').css('display', 'block');
		$(this).css('-moz-border-radius-bottomright', 0);
		$(this).css('-webkit-border-bottom-right-radius', 0);
	}, function()
	{
		$(this).parent().find('div.login-box').css('display', 'none');
		$(this).css('-moz-border-radius-bottomright', 5 + 'px');
		$(this).css('-webkit-border-bottom-right-radius', 5 + 'px');
	});

	//----------------------------------------------------------------------------------
	// slidedesk contents
	//----------------------------------------------------------------------------------
	
	$('div.slide_content.hidden').slideUp(0);
	
	$('div.profile_search h1').toggle(function() {
		
		if($(this).parent().find('div.slide_content').is(':visible')) {
			$(this).addClass('hidden');
			$(this).parent().find('div.slide_content').slideUp(500);
		} else {
			$(this).removeClass('hidden');
			$(this).parent().find('div.slide_content').slideDown(500);
		}
			
	}, function() {
		
		if($(this).parent().find('div.slide_content').is(':visible')) {
			$(this).addClass('hidden');
			$(this).parent().find('div.slide_content').slideUp(500);
		} else {
			$(this).removeClass('hidden');
			$(this).parent().find('div.slide_content').slideDown(500);
		}
			
	});

	$('div.profile_tags h1').toggle(function() {
		
		if($(this).parent().find('div.slide_content').is(':visible')) {
			$(this).addClass('hidden');
			$(this).parent().find('div.slide_content').slideUp(500);
		} else {
			$(this).removeClass('hidden');
			$(this).parent().find('div.slide_content').slideDown(500);
		}
			
	}, function() {
		
		if($(this).parent().find('div.slide_content').is(':visible')) {
			$(this).addClass('hidden');
			$(this).parent().find('div.slide_content').slideUp(500);
		} else {
			$(this).removeClass('hidden');
			$(this).parent().find('div.slide_content').slideDown(500);
		}
			
	});
	
	//----------------------------------------------------------------------------------
	// jquery address plugin
	//----------------------------------------------------------------------------------

  $.address.init(function(event) {} ).change(function(event)
	{
		if(event.queryString == undefined) {
			
			$('table.profile_activists_results td').animate({ opacity : 0.25 }, 500);
			$('table.profile_activists_pagination p').addClass('load');
		
			setTimeout(function()
			{					
				jQuery.post("index.php?article_id=135",
				{
					networktype : $('div.profile_network').attr('id'),
					next				: 1,
					type				: 'newest'
				},
				function(data)
				{
					$('table.profile_activists_pagination p').removeClass('load');
					$('ul.profile_results_header p').removeClass('load');
					$('ul.profile_results_header p').addClass('close');
					$('div.profile_network').empty();
					$('div.profile_network').append(data);
					$('div.profile_network').not(':visible').animate({ height : 'toggle', opacity: 1 }, { easing: 'easeOutExpo', duration: 500 });
					$('table.profile_activists_results tr td').eq(3).css('border', 'none');
					$('table.profile_activists_results td').css({ opacity : 0.25 }).animate({ opacity : 1 }, 500);
				});
			}, 1000);
		
			return false;
			
		} else {
			var vars = [], hash;
			
			var hashes = event.queryString.slice(event.queryString.indexOf('?') + 1).split('&');
			
			for(var i = 0; i < hashes.length; i++)
			{
					hash = hashes[i].split('=');
					vars.push(hash[0]);
					vars[hash[0]] = hash[1];
			}
	
			Community.Profile.Paginate(vars["type"], '', vars["next"], event);
			
			setTimeout(function() {
				$('div.profile_network').not(':visible').animate({ height : 'toggle', opacity: 1 }, { easing: 'easeOutExpo', duration: 500 });
					$('ul.profile_results_header p').removeClass('load');
						$('ul.profile_results_header p').addClass('close');
			}, 1000);
		}
		return false;
  });

	//----------------------------------------------------------------------------------
	// grid padding rescue
	//----------------------------------------------------------------------------------
	

}); 