$(document).ready(function(){
	
	$(".cycle_container").cycle(
		{
			timeout: 5000,
			fx: 'fade',
			speed: 500,
			pager:"#nav"
		   
		});
	
	/*----------------------- Start Link Page Pager -----------------------*/
	$(".link_next").click(function(){
		var i = 0;
		var activeelem = 0;
		var totalChilds = 0;
		var box_container = $(this).parent().next();
		$(box_container).children().each(function(){
			if($(this).css('display') == 'block'){
				activeelem = i;
			}
			i++;
		});
		totalChilds = i;
		i = 0;
		$(box_container).children().each(function(){
			if(i == activeelem){
				$(this).hide('fast');
				$(this).next().show('fast');
				
			}
			i++;
		});
		activeelem = 0;
		i= 0;
		$(box_container).children().each(function(){
			if($(this).css('display') == 'block'){
				activeelem = i;
			}
			i++;
		});
		if(activeelem == totalChilds-1){
			$(box_container).prev().children(".link_prev").show();
			$(box_container).prev().children(".link_next").hide();
		} else{
			$(box_container).prev().children(".link_prev").show();
		}
		fix_height();
		return false;
		
	});
	
	$(".link_prev").click(function(){
		var i = 0;
		var activeelem = 0;
		var totalChilds = 0;
		var box_container = $(this).parent().next();
		$(box_container).children().each(function(){
			if($(this).css('display') == 'block'){
				activeelem = i;
			}
			i++;
		});
		totalChilds = i;
		i = 0;
		$(box_container).children().each(function(){
			if(i == activeelem){
				$(this).hide('fast');
				$(this).prev().show('fast');
			}
			i++;
		});
		activeelem = 0;
		i= 0;
		$(box_container).children().each(function(){
			if($(this).css('display') == 'block'){
				activeelem = i;
			}
			i++;
		});
		if(activeelem == 1){
			$(box_container).prev().children(".link_prev").hide();
			$(box_container).prev().children(".link_next").show();
		} else {
			$(box_container).prev().children(".link_next").show();
		}
		fix_height();
		return false;
		
	});
	/*----------------------- End Link Page Pager -----------------------*/
	
   
});
function home_loaded(){
	
	var elements1=new Array(3);
	elements1[0]="#box1";
	elements1[1]="#box2";
	elements1[2]="#box3";
	$.balanceElementHeight(elements1);
	
	var elements2=new Array(3);
	elements2[0]="#box4";
	elements2[1]="#box5";
	elements2[2]="#box6";
	$.balanceElementHeight(elements2);
};
function inner_loaded(){
	$(".page").balanceChildrenHeight();
};
function links_loaded(){
	fix_height();
};
function fix_height(){
	$("#container_links").balanceChildrenHeight();
};

