$(document).ready(function () {
    init_tab_clicks()
	images_init()
});

/* Tab Clicks
***************************/
function init_tab_clicks(){
	$('#tabs a').click(function () { 
		var tab_id = this.id.slice(6,7)					 
    	slide_tab(tab_id)
		swap_img(tab_id)
		return false
    });
    
    $('#tabs .not_selected').mouseover(function(){
    	$("#"+this.id).css({
    		backgroundPosition: "left center"
    	})

    })
    
     $('#tabs .not_selected').mouseout(function(){
    	$("#"+this.id).css({
    		backgroundPosition: "left top"
    	})
    })
}


/* Slide tabs
***************************/
function slide_tab(tab_id){
	//Get the height of the container tabs
	var scroll_height = $('#tab_content_1').outerHeight()
	//Calculate the position to move the,m to
	var move_by = ((tab_id - 1) * scroll_height) * -1
	
	//Do the animation
	$("#tab_container").animate({ 
        marginTop: move_by+"px"
      }, "250", "easeInOutCubic", function(){top_img(tab_id)} );
	
}

function swap_img(id){
	
	/*
	If it has the class selecetd then change it to not_selected
	and vice versa
	*/
	if($("#tab_"+id).hasClass("selected") != true){
		for(i=0; i<3; i++){
			n = i+1
			$("#tab_"+n).addClass("not_selected");
			$("#tab_"+n).removeClass("selected");
		}
		$("#tab_"+id).removeClass("not_selected");
		$("#tab_"+id).addClass("selected");	
	}
	
}

function top_img(me){
	this_id = me
	if(this_id != current_slide){
		
		var id = me-1
		
		load_flash(id)
		
		// //All
		// 		$("#main div").css({ zIndex: 1 });
		// 		//Current
		// 		$("#main #main"+current_slide).css({ zIndex: 3 });
		// 		//this
		// 		$("#main #main"+this_id).css({ zIndex: 2 });
		// 		
		// 		//Set all to be 100
		// 		$("#main div").fadeTo(0, 1);
		// 		
		// 		//Fade current to 0
		// 		$("#main #main"+current_slide).fadeTo("fast", 0);
		
		
		current_slide = this_id
	}
}


var current_slide = 1
function images_init(){
							 	
	for(i=0; i<3; i++){
		n = i+1
		if(n != current_slide){
			$("#main #main"+n).fadeTo(0, 1);	
		}
	}
    
    /*$("#tabs a").click(function () {
		var this_id = this.id.toString().split("_")
		this_id = this_id[2]
		
		if(this_id != current_slide){
			
			
			//All
			$("#main div").css({ zIndex: 1 });
			//Current
			$("#main #main"+current_slide).css({ zIndex: 3 });
			//this
			$("#main #main"+this_id).css({ zIndex: 2 });
			
			//Set all to be 100
			$("#main div").fadeTo(0, 100);
			
			//Fade current to 0
			$("#main #main"+current_slide).fadeTo("fast", 0);
			
			
			current_slide = this_id
		}
		
		return false;
      
    });*/

}