/* 
 * Tab.js 
 * version 2.1.OSC
*/

var currentTab = null;
var inSlide = false;
$(document).ready(
	function()
	{
		var url, tab = 0, tabIteration = 0;
		$('#scroll').ScrollToAnchors(500);
		
		url = window.location.href.split("#");
		if (url.length == 2 && url[1].indexOf('-fx') > 0) {
			currentTab = $('#' + url[1].substr(0, url[1].length-3));
			if (currentTab.size() == 1) {
				$('#fx div').each(
					function(iteration)
					{
						if(this === currentTab.get(0)) {
							tabIteration = iteration;
						}	
					}
				);
			}
		}
		
		if(!currentTab) {
			currentTab = $('#fx div:first');
		}
		currentTab.SlideToggleUp(400);
		$('#tabs2 a')
			.eq(tabIteration).addClass('active')
			.end()
			.bind('click', switchTab);
			
			$('#tabs2 li')
			.eq(tabIteration).addClass('on')
			.end()

		
	}
);

 $("#rev_bt").click(function(){
	tabName ='#recenzje';
	if (inSlide == false && currentTab.get(0) != $(tabName).get(0)) {
		$('#tabs2 a').removeClass('active');
		$('#tabs2 li').removeClass('on');
		$('#recenzje-fx').addClass('active');
		$('#rev').addClass('on');
		inSlide = true;
		currentTab.SlideToggleUp(400, function()
			{
								currentTab = $(tabName).SlideToggleUp(400,function(){inSlide=false;})	
		} );
		return false;
	}	else {
		return false;
	}
 });
 
 
 jQuery.fn.corner = function(options) {
    
        
        var settings = {
          tl: { radius: 10 },
          tr: { radius: 10 },
          bl: { radius: 10 },
          br: { radius: 10 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"] };
        if ( options && typeof(options) != 'string' )
            jQuery.extend(settings, options);


    return this.each(function() {
        new curvyObject(settings,this).applyCorners();
        //new curvyCorners(settings, this ).applyCornersToAll();
	});   
            
};

$("#tabs2 li").click(function(){
   $(this).addClass('on');
   return false;
 });
 
var switchTab = function()
{
	var tabName = this.href.split('#')[1];
	this.blur();
	if (inSlide == false && currentTab.get(0) != $('#' + tabName.substr(0, tabName.length-3)).get(0)) {
		$('#tabs2 a').removeClass('active');
		$('#tabs2 li').removeClass('on');
		$(this).addClass('active');
		inSlide = true;
		currentTab.SlideToggleUp(
			400,
			function()
			{
				currentTab = $('#' + tabName.substr(0, tabName.length-3)).SlideToggleUp(400, function(){inSlide=false;});
			}
		);
	} else {
		return false;
	}
};
