/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshow li.active');

    if ( $active.length == 0 ) $active = $('#slideshow li:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow li:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


function mostPopularTab2(a){
	$('#top_news_tabs'+a+' li').click(function(){
		var tabId=$(this).attr('id');
		
		$('#top_news_panels_box'+a+' li.top_news_panels').addClass('hidden');
		$('#'+tabId+'_panel').removeClass('hidden');		
		$('#top_news_tabs'+a+' li').removeClass('selectedTab');
		$(this).addClass('selectedTab');

	});
}

function carouselIt(){
	var box_number=0;
	var kids=$('#thumb_box').children();
	var kidsLength=kids.length/7;
	var kidsLength10=Math.ceil(kidsLength);
	var boxWidth=441*kidsLength10
	$('#thumb_box').css({'width': boxWidth});
	
	$('#thumbNext').click(function(){
		box_number++;
		if(box_number<kidsLength10){
		
		}else{
			box_number=0;
		}
		var goToLeft = -441*box_number;

		$('#thumb_box').animate({
			marginLeft: goToLeft
		},500);
		
		return false;

	});
	
	$('#thumbPrev').click(function(){
		box_number--;
		if(box_number<0){
			box_number=kidsLength10-1;
		}
		var goToRight = -441*box_number;
		

		$('#thumb_box').animate({
			marginLeft: goToRight
		},500);

		return false;
	});
}


jQuery(document).ready(function() {
//lavaLamp
	/*	$(".lavaLamp").lavaLamp({ fx: "easeInCirc", speed: 100});

	});*/
//slideSwitch
    setInterval( "slideSwitch()", 5000 );
//photoDisplay
	$("#photoDisplay").hover(
      function () {
			$(this).find(".child_description").slideToggle('slow');
			
      }, 
      function () {
			$(this).find(".child_description").slideToggle('slow');
      });
//thumbnail
	$('.thumbnail').click(function(){
		$(this).siblings('.active').removeClass('active');
		$(this).siblings('.op1').removeClass('op1');
		$(this).addClass('active');

		$('[id=i_main_'+this.id+']').siblings('.i_mainShow').css({'display':'none'}).removeClass('i_mainShow');
		$('[id=i_main_'+this.id+']').fadeIn('slow').addClass('i_mainShow');
	});
//carouselIt
	carouselIt();
//mostPopularTab2	
	mostPopularTab2(1);
	mostPopularTab2(2);
//Form letters
	$("textarea#comments_textarea").dodosTextCounter(1200, {counterDisplayElement: "em",counterDisplayClass: "comments_characters"});

	/*var current_characters=$('#comments_textarea').val().length;
	var characters_left=1200-current_characters;
	
	$('#test').text(current_characters);
	$('#comments_characters em').text(characters_left);
	
	$('#comments_textarea').keyup(function(){
		current_characters=$(this).val().length;
		characters_left=1200-current_characters;
		$('#comments_characters em').text(characters_left);
		
		$('#test').text(current_characters);
		
	});*/
	
//Advertising
	$('.advertising-image').hover(
		function(){
			$(this).find('.ad_intro').slideToggle('slow');
		},
		function(){
			$(this).find('.ad_intro').slideToggle('slow');
		});
		
/* font-size ----------------------------------------------------------------------*/
		var fontSize=13;
		$('#text_smaller').click(function(){
			$('#attribute_body p ').css({'font-size':'85%'});
			$('#attribute_body h2').css({'font-size':'215%'});
			$('#attribute_body h3').css({'font-size':'138.5%'});
			$('#attribute_body h4').css({'font-size':'123.1%'});
			$('#attribute_body h5').css({'font-size':'123.1%'});
			$('#attribute_body h6').css({'font-size':'100%'});

		});
		$('#text_middle').click(function(){
			$('#attribute_body p ').css({'font-size':'100%'});
			$('#attribute_body h2').css({'font-size':'230%'});
			$('#attribute_body h3').css({'font-size':'153.9%'});
			$('#attribute_body h4').css({'font-size':'138.5%'});
			$('#attribute_body h5').css({'font-size':'138.5%'});
			$('#attribute_body h6').css({'font-size':'123.1%'});

		});
		$('#text_larger').click(function(){
			$('#attribute_body p').css({'font-size':'116%'});
			$('#attribute_body h2').css({'font-size':'245%'});
			$('#attribute_body h3').css({'font-size':'167%'});
			$('#attribute_body h4').css({'font-size':'153.9%'});
			$('#attribute_body h5').css({'font-size':'153.9%'});
			$('#attribute_body h6').css({'font-size':'146.5%'});
	
		});
	
});
