$(document).ready(function(){
 	
	DD_belatedPNG.fix('#mask, ul.downloads li');
	/*------------------- Galeries ------------------------------------------------------------------------*/
	//----------- Main Slideshow
	
	$('#slideshow').cycle({ 
		fx:     'fade', 
		speed:   2000, 
		timeout: 4000, 
		next:   '#next',
        prev:   '#prev',
		before:  onBefore, 
		after:   onAfter,
		cleartype:  1
	 });
	
	function onBefore() { 
		$('#output').animate({  
			height: "0"
		}, 500 );
		$('#output').html("");
	}
	
	function onAfter(curr,next,opts) { 
		if (this.alt != '') {
			$('#output').animate({ 
				height: "36px"
			}, 800 );
			//console.log(opts.slideCount);
			$('#output').append('<p>' + this.alt + '</p>'); 

		}
		if (opts.slideCount==1) {
			$('#slideshow').cycle('stop');
			return false;
		}
	}
	
	$('#pause').click(function() { $('#slideshow').cycle('pause'); return false; });
    $('#play').click(function() { $('#slideshow').cycle('resume'); return false; });

	/*-----------------------------------------------------------------------------------------*/
	//$('#content p:first').css('font-size','14px');
	
	$('h2').each(function() {
		$(this).wrapInner('<span></span>');
	});
	
	if (!$('#leftSidebar').children().length) {
		$('#leftSidebar').hide();
		$('#content').width(913);
	}	
	
	if ($('span.date').length) {
		$('h3').css('padding-bottom','0');
	}	
	
	$('ul#home_news_list li:first').css('margin-top','0');
	
	$('#banner').click(function() {
		location.href = "index.htm" 
	});

	equalHeight($('.list_item'));
	
	/*-------------------------------------------------------------------------------------------*/
	//Newsletter form validation
	$("form#subscribeForm").submit(function() {
		if ( ( $("input#name").val() == "") || ($("input#name").val() == "Your name")) {
			//alert('Please type your name');
			$('span#valResult').html('Please type your name');
			return false;
		}

		if ( ( $("input#ikjltr-ikjltr").val() == "") || ($("input#ikjltr-ikjltr").val() == "Your email address")) {
			//alert('Please type your email address');
			$('span#valResult').html('Please type your email address');
			return false;
		} else {
			var rules  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if ($("input#ikjltr-ikjltr").val().match(rules)) {
				return true;
			} else {
				//alert('You povided wrong email address');
				$('span#valResult').html('Email address is not valid');
				return false;
			}
		}
		
		if ( ( $("input#cm-f-ykiuky").val() == "") || ($("input#cm-f-ykiuky").val() == "Your company name")) {
			$('span#valResult').html('Please type your company name');
			return false;
		}
		
		
    });
	/*------------------------------------------------------------------------------------------------------*/
	//Search form validation
	$("form#ajaxSearch_form").submit(function() {
		if ( ($("input#ajaxSearch_input").val() == "") || ($("input#ajaxSearch_input").val() == "Search here...")){
			//alert('Please type your name');
			alert('At least 3 characters are required for your search term');
			return false;
		}
    });

	/*-------------------------------------------------------------------------------------------------------*/
	//Profiles accordion
	$('div.desc').eq(0).show();
	$('span.about').eq(0).addClass('active');
	
	$('span.about').click(function() {
		$(this).addClass('active');
		var target = $(this).parents('div.top').next('div.desc');
		target.slideDown();
		$('div.desc').not(target).slideUp().prev('div.top');
		$('span.about').not($(this)).removeClass('active');
	});

}); //Close document.ready

$(window).bind("load", function() {							
    //-----------  Preload images for 
    //-----------  Preload images for 
	
	$('.loading').each(function () {
		$(this).hide();
	});
	$('#banner').fadeIn('slow');
	$('#slideshowWrapper').fadeIn('slow');

});

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
