$(document).ready(function() {
	
	$('#navigation_bg').fadeTo(0,0.75);
	$('.panels_background').fadeTo(0,0.3);
	$('#contact_container').fadeTo(0,0.75);
	$('#content_home_background').fadeTo(0,0.75);
	$('#contact_container').css({backgroundColor:'#ec008c'});
	$('.panels_background').css({backgroundColor:'#ec008c'});
	
	if($.browser.msie && ($.browser.version == 6.0)) {
		$('#logo').ifixpng();
		
		$('#navigation a').each(function() {
			$(this).css({
				backgroundPosition: ($(this).width()+30)+'px 1px'});
		});
		$('#navigation a').ifixpng();
		$('#contact_form .submit').ifixpng();
		
	}
	
	/* SCROLLER */	
	$('#page_content .text_section .scroller').each(function() {
		$('#page_content .text_section .scroller').css({overflow:'hidden'});
		$('#page_content .text_section .scroller p:last').addClass("last_p");
		
		var scrollerHeight = $(this).height();
		
		if($('#page_content #content_home').length > 0) {
			scrollerHeight = $(this).height()-($('#page_content #content_home h1').height()+10);
		} else if($('#page_content #main_panel').attr('id') == $(this).parent().parent().attr('id') ) {
			scrollerHeight = $(this).height()-($('#page_content #main_panel h1').height()+10);
		}
		
		$(this).html('<div class="height_div"'+$(this).html()+'</div>');
		if($(this).children().height() > scrollerHeight) {
			
			if(scrollerHeight > 195) scrollerHeight = 195;
		
			if($('#page_content #content_home').length > 0) {
				if($(this).height()+($('#page_content #content_home h1').height()+30)>195) scrollerHeight = $(this).height()-($('#page_content #content_home h1').height()+30);
			} else if($('#page_content #main_panel').attr('id') == $(this).parent().parent().attr('id') ) {
				if($(this).height()+($('#page_content #main_panel h1').height()+10) > 195) scrollerHeight = $(this).height()-($('#page_content #main_panel h1').height()+30);
			}
			if($.browser.safari || $.browser.msie) {
				$(this).css({overflow : 'hidden', height : scrollerHeight});
			}
			else {
				$(this).css({overflow : 'hidden', height : scrollerHeight});
			}
						
			$(this).parent().append('<div class="buttons"><a href="#" class="more">more<span class="arrow"></span></a><a href="#" class="back">back<span class="arrow"></span></a></div>');
		}
	});
			
	if($.browser.msie && ($.browser.version == 6.0)) {
		$('#page_content .text_section .buttons .arrow').ifixpng();
	}
	
	$('#page_content .text_section .buttons a').click(function() {
		if($(this).hasClass('more')) { $(this).parent().prev().scrollTo('+=100px', 1000); } 
		else { $(this).parent().prev().scrollTo('-=100px', 1000); }
		return false;
	});
	
	/* IMAGE GALLERY */
	$('#page_content .image div').each(function() {
		$(this).children().hide();
		$(this).children(':last').show().addClass('selectedImage');

		var imageCount = 0;
		$(this).children().each(function() { imageCount = imageCount + 1 });
		if(imageCount > 1) {
			
			if($.browser.msie && ($.browser.version == 6.0)) {
				var nextButton = 'next-image.png';
				var prevButton = 'prev-image.png';
			} else {
				var nextButton = 'next-image-trans.png';
				var prevButton = 'prev-image-trans.png';
			}
			
			$(this).parent().append('<img src="'+base_url+'public/imgs/'+prevButton+'" alt="previous image" class="prev" /><img src="'+base_url+'public/imgs/'+nextButton+'" alt="next image" class="next" />');

			$(this).parent().each(function() { 
				if(!$(this).parent().next().hasClass('panel')) {
					$(this).children('.next').css({right : '15px'});
					$(this).children('.prev').css({right : '205px'});
				}
			});
		}
	});
			
	$('#page_content .image .next, #page_content .image .prev').click(function() {
		
		var $currentImage = $(this).parent().children('div').children('.selectedImage');
		
		if($(this).hasClass('next')) {
			var $newImage = $currentImage.prev();
			if(!$newImage.length) $newImage = $currentImage.parent().children(':last');
		}
		else {
			var $newImage = $currentImage.next();
			if(!$newImage.length) $newImage = $currentImage.parent().children(':first');
		}
		
		$currentImage.hide().removeClass('selectedImage');
		$newImage.show().addClass('selectedImage');
	});
	
	$('.newWindow').click(function() { 
		window.open(this.href, 'new_window');
		return false;
	});
	
});
