$(document).ready(function() {
	$('.vitrin_tab').click(function (e){
        tabId = this.hash;
        holderId = $(this).parent().attr('id').replace("tab-holder-","");
        
        checkURL(tabId,$(this).parent().next());
        
        $("#tab-holder-"+holderId+" a").removeClass('Aktif');
        $(this).addClass('Aktif');
	});
	$('.vitrin_tab_ileri').click(function (e){
        lasturl="";
        
        blokId = $("#tab-"+this.hash.replace("#sekme","")).attr("value");
                
        checkURL(blokId+'_ileri',$(this).parent().prev());
	});
	$('.vitrin_tab_geri').click(function (e){
        lasturl="";
        
        blokId = $("#tab-"+this.hash.replace("#sekme","")).attr("value");

        checkURL(blokId+'_geri',$(this).parent().prev());
	});
});

var blokId="";
var blokId_="";
var lasturl="";

function checkURL(hash,holder)
{
	if(!hash) hash=window.location.hash;

	if(hash != lasturl) {
		lasturl=hash;
		// FIX - if we've used the history buttons to return to the homepage,
		// fill the pageContent with the default_content
		if(hash!="")
		loadPage(hash,holder);
	}
}

function loadPage(url,holder) {
	url=url.replace('#sekme','');
	
	$("#loading-"+blokId_.replace('#sekme','')).css('visibility','visible');
	$.ajax({
		type: "POST",
		url: "ajax.php?m=Block&fn=tabContent",
		data: 'blok='+url,
		dataType: "html",
		//cache: false,
		success: function(msg){
        if(parseInt(msg)!=0)
			$(holder).hide().html(msg).fadeIn(200);
			//$("#tab-holder-"+url+" .Loading").css('visibility','hidden');
		}
	});
}


function newsscoller(prev,id) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery'+id+' a.selected').length ? $('#gallery'+id+' a.selected') : $('#gallery'+id+' a:first');
	var current_excerpt = $('#excerpt'+id+' li.selected').length ? $('#excerpt'+id+' li.selected') : $('#excerpt'+id+' li:first');

	//if prev is set to 1 (previous item)
	if (prev) {
		
		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery'+id+' a:last');
		var next_excerpt = (current_excerpt.prev().length) ? current_excerpt.prev() : $('#excerpt'+id+' li:last');
	
	//if prev is set to 0 (next item)
	} else {
		
		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery'+id+' a:first');
		var next_excerpt = (current_excerpt.next().length) ? current_excerpt.next() : $('#excerpt'+id+' li:first');
	}

	//clear the selected class
	$('#excerpt'+id+' li, #gallery'+id+' a').removeClass('selected');
	
	//reassign the selected class to current items
	next_image.addClass('selected');
	next_excerpt.addClass('selected');

	//Scroll the items
//	$('#mask-gallery'+id).scrollTo(next_image, 800);
//	$('#mask-excerpt'+id).scrollTo(next_excerpt, 800);
}

