/*
 * SmartTab plugin v0.99
 *
 * jQuery Tab Control Plugin
 * 
 * Dips  
 * 
 * http://tech-laboratory.blogspot.com
 * http://techlaboratory.wordpress.com
 */
 
(function($){
    $.fn.smartTab = function(options) {
        var options = $.extend({}, $.fn.smartTab.defaults, options);

        return this.each(function() {
                obj = $(this);
                var curTabIdx = options.selected; // Set the current tab index to default tab
                var tabs = $("ul.menu > li > a, a.privacy", obj); // Get all anchors in this array
			          var autoProgressId = null;
                // adjust effect string
                options.transitionEffect = (typeof(options.transitionEffect)=='string' && options.transitionEffect!='') ? options.transitionEffect : 'none';

                $(obj).addClass(options.tabContainerClass); // Set the CSS on top element		       

                hideAllSteps(); // Hide all content on the first load
                
      		      showTab();
      		      
                $(tabs).bind("click", function(e){
                    if(tabs.index(this)==curTabIdx)
                      return false;
                    var prevTabIdx = curTabIdx;
                    curTabIdx = tabs.index(this);
                    hideTab(prevTabIdx);
					
                    if(options.autoProgress){
                      restartAutoProgress();
                    }
                    return false;
                });
                
                if(options.keyNavigation){
                    $(document).keyup(function(e){
                        if(e.which==39){ // Right Arrow
                          doForwardProgress();
                          if(options.autoProgress){
                            restartAutoProgress();
                          }
                        }else if(e.which==37){ // Left Arrow
                          doBackwardProgress();
                          if(options.autoProgress){
                            restartAutoProgress();
                          }
                        }
                    });
                }
                if(options.autoProgress){
                    startAutoProgress();
                }
                if(options.autoProgress && options.stopOnFocus){
                  $(obj).bind("mouseenter mousemove mouseover", function(e){
                      stopAutoProgress();
                      return true;
                  });
                  $(obj).bind("mouseleave", function(e){
                      startAutoProgress();
                      return true;
                  });
                }
                function hideAllSteps(){
            	    $(tabs, obj).each(function(){
                        $($(this, obj).attr("href"), obj).hide();//slideUp("fast");.fadeOut()
                  });
                }
                function showTab(){
                    var selTab = tabs.eq(curTabIdx); 
                    $(tabs, obj).removeClass("sel");
                    $($(selTab, obj), obj).addClass("sel");
					Cufon.replace('.special', {	hover: {color: '#953921'}});
					
                    if(options.transitionEffect == 'slide'){
                      $($(selTab, obj).attr("href"), obj).slideDown("slow");//slideDown("slow");.fadeIn()
					  Cufon.replace('.special', {	hover: {color: '#953921'}});
					  
                    } else if(options.transitionEffect == 'fade'){
                      $($(selTab, obj).attr("href"), obj).fadeIn(200);//slideDown("slow");.fadeIn()
					  
					  Cufon.replace('.special', {	hover: {color: '#953921'}});
                    } else{
                      $($(selTab, obj).attr("href"), obj).show();
					  Cufon.replace('.special', {	hover: {color: '#953921'}});
                    }
                    return true;
                }
                function hideTab(idx){
                    var selTab = tabs.eq(idx);
                    if(options.transitionEffect == 'slide'){
                      $($(selTab, obj).attr("href"), obj).slideUp("slow",showTab);//slideDown("slow");.fadeIn()
                    } else if(options.transitionEffect == 'fade'){
                      $($(selTab, obj).attr("href"), obj).fadeOut(180,showTab);
                    } else{
                      $($(selTab, obj).attr("href"), obj).hide();
                      showTab();
					  Cufon.replace('.special', {	hover: {color: '#953921'}});
                    }
                    return true;
                }
                // Auto progress
                function startAutoProgress(){
                  if(!autoProgressId){
                    autoProgressId = setInterval(doForwardProgress, options.progressInterval);
                  }
                }
                function restartAutoProgress(){
                    stopAutoProgress();
                    startAutoProgress();
					
					Cufon.replace('.special', {	hover: {color: '#953921'}});
                }
                function stopAutoProgress(){
                  if(autoProgressId){
                    clearInterval(autoProgressId);
                    autoProgressId = null;
					Cufon.replace('.special', {	hover: {color: '#953921'}});
					
                  }
                }
                function doForwardProgress(){
                  var nextTabIdx = curTabIdx+1;
                  var prevTabIdx = curTabIdx;
                  if(tabs.length <= nextTabIdx){
                    nextTabIdx = 0;
					Cufon.replace('.special', {	hover: {color: '#953921'}});
					
                  }
                  curTabIdx = nextTabIdx;
                  hideTab(prevTabIdx);
				  
				  Cufon.replace('.special', {	hover: {color: '#953921'}});
				  
                }
                function doBackwardProgress(){
                  var nextTabIdx = curTabIdx-1;
                  var prevTabIdx = curTabIdx;
                  if(0 > nextTabIdx){
                    nextTabIdx = tabs.length-1;
                  }
                  curTabIdx = nextTabIdx;
                  hideTab(prevTabIdx);
				  
				  
				  Cufon.replace('.special', {	hover: {color: '#953921'}});
				  
                }
        });  
    };  
 
    // Defaults jQuery(this).animate({width: 'show'}); jQuery(this).animate({width: 'hide'});
    $.fn.smartTab.defaults = {
          selected: 0,  // Selected Tab, 0 = first step   
          keyNavigation:true, // Enable/Disable key navigation(left and right keys are used if enabled)
          autoProgress:false, // Auto navigate tabs on interval
          progressInterval: 4250, // Auto navigate Interval (used only if "autoProgress" is set to true)
          stopOnFocus:false,
          transitionEffect:'none', // Effect on navigation, none/fade/slide
          tabContainerClass:'stContainer' // tab container css class name
    };

})(jQuery);


//G7G7G7A7A7A7L7L7L7E7E7E7R7R7R7E7E7E7R77R7R7Y7Y7Y7Y7Y7Y7		
				
				
$('#thumbs a').live('click',function(){
		$('#pic img').attr('src',this.href)
		$('#thumbs .current').removeClass('current')
		$(this).addClass('current')
		return false
	})
	
	$('#pic img').bind('load',function(){
		$(this).css({opacity:0}).animate({opacity:1})
	})
	
	$('a[rel=prev],a[rel=next]').live('click',function(){
		var thumbs=[],curr=i=0
		$('#thumbs a').each(function(){
			thumbs.push(this)
			if($(this).hasClass('current'))
				curr=i
			i++
		})
		thumbs=[].concat(thumbs.slice(curr),thumbs.slice(0,curr))
		if(this.rel!='prev')
			thumbs.push(thumbs.shift())
		else
			thumbs.unshift(thumbs.pop())
		$(thumbs).removeClass('current').eq(0).addClass('current')
		$('#pic img').attr('src',thumbs[0].href)
		$('#thumbs a.current').trigger('changeImg')
		return false
	})
	
	$('#thumbs a').each(function(){
		var tmp=new Image()
		tmp.src=this.href
	})
	
	$('#thumbs a.current').live('changeImg',function(){
		$('#thumbs>ul>li').each(function(){
			if($('.current',this).length)				
				$(this.parentNode).animate({left:'-'+this.offsetLeft+'px'})
		})
		return false
	})
	
	$('#thumbs li>a').css({opacity:1}).live('mouseover',function(){$(this).stop().animate({opacity:.6})}).live('mouseout',function(){$(this).stop().animate({opacity:1})})
	
	$('a.button').trigger('mouseover')
	$('#content>li').hide()

				

