function formatText(index, panel) {
	  return index + "";
    }

$(function () {   
	
	$('li:last-child, .two-col .col:last-child, .three-col .col:last-child, .four-col .col:last-child, tr:last-child, td:last-child').addClass('last');
	$('li:first-child, .two-col .col:first-child, .three-col .col:first-child, .four-col .col:first-child').addClass('first');
	
	$('tr:even').addClass('even');
	
	$('#nav li a').each(function(index) {
	    if($(this).text().length > 23) {
			$(this).parent().addClass('large');
		}
	});
	
	$('#nav li.large.active').addClass('large-active');
	
	
	$(".lightbox-gallery").fancybox({
		'width'				: 867,
		'height'			: 520,
		'padding'           : 7,
		'overlayOpacity'    : 0.5,
		'overlayColor'      : '#000',
		'scrolling'         : 'no',
		'autoScale'         : false,
		'type'				: 'iframe',
		'centerOnScroll'    : true     
	});
	
    $('.slider').anythingSlider({
        easing: "easeInOutExpo",     
        autoPlay: false,             
        delay: 3000,                 
        startStopped: true,          
        animationTime: 600,          
        hashTags: true,              
        buildNavigation: true,       
		pauseOnHover: true,          
		startText: "Go",             
     stopText: "Stop",               
     navigationFormatter: formatText 
    });
    
    $("#slide-jump").click(function(){
        $('.slider').anythingSlider(4);
    });

	loader();
});

/* ------------ SLIDESHOW */
var j = 0;

function loader(){
	
	var img = new Image();
	$(img).load(function(){
		var el = $("li:eq("+j+")", "#superslideshow");
		$(el).html(this);
		if(j<$("#superslideshow .images li").length){
			j++;
			if(j==$("#superslideshow .images li").length-1){
				slideShow();
			}
			loader();
		}
	}).attr('src',$("#superslideshow li:eq("+j+") img").attr('src'));
}

function slideShow() {
	$('#superslideshow .images li').hide();
	$('#superslideshow li:first').fadeIn("slow");
	interval = setInterval('gallery()',4000);
	$('.home_slide #links a:first').addClass('current');
}

var interval;

function gallery() {
	var current = $('#superslideshow li.show');
	$('#superslideshow li').fadeOut(1000);
	$('#superslideshow li').removeClass('show');
	var next = ((current.next().length) ? ((current.next().hasClass('clickk'))? $('#superslideshow li:first') :current.next()) : $('#superslideshow li:first'));
	next.fadeIn(1000);
	next.addClass('show');
	var lien = next.find('a').attr('class');

}

/* ------------ TABS OPEN ACCOUNT */
$(document).ready(function() {
	$(".tabs li").click(function(){
		$(".acform").hide();
		$(".tabs li").removeClass("active");
		$(this).addClass("active");
		story = $(this).attr('id');
		$("div."+story).show();
		return false;
	});
	$(".box-link").click(function(){
		window.location=$(this).find("a").attr("href");
	});

	/**/

	$("#regions").change(function(){
		 $('#cities').html('<img src="/_img/assets/ajax-loader.gif" alt="loader" />');
		 var region_id = $(this).val();		 
		 $('#cities').load('/ajax/get_related_agencies', {'region_id': region_id});
	});


	$('.blank').click(function() {
		window.open($(this).attr('href'));
		return false;
	});


}); 


