/*
By Gonten.com
E-mail: mail@gonten.com
*/
$(function(){
   $("#tab1").click(function(){
		$("#con1").show(); 
		$("#con2").hide();
		$("#con3").hide();
		$("#tab1").addClass("this");
		$("#tab2").removeClass("this");
		$("#tab3").removeClass("this");
   });
   $("#tab2").click(function(){
		
		$("#con1").hide();
		$("#con2").show(); 
		$("#con3").hide();
		$("#tab1").removeClass("this");
		$("#tab2").addClass("this");
		$("#tab3").removeClass("this");
   });
   $("#tab3").click(function(){
		
		$("#con1").hide();
		$("#con2").hide();
		$("#con3").show(); 
		$("#tab1").removeClass("this");
		$("#tab2").removeClass("this");
		$("#tab3").addClass("this");
   });
   
   $("#goteytab1").mouseover(function(){
		$("#case1").show(); 
		$("#case2").hide();
		$("#case3").hide();
		$("#case4").hide();
		$("#goteytab1").addClass("this");
		$("#goteytab2").removeClass("this");
		$("#goteytab3").removeClass("this");
		$("#goteytab4").removeClass("this");
   });
   $("#goteytab2").mouseover(function(){
		
		$("#case1").hide();
		$("#case2").show(); 
		$("#case3").hide();
		$("#case4").hide();
		$("#goteytab1").removeClass("this");
		$("#goteytab2").addClass("this");
		$("#goteytab3").removeClass("this");
		$("#goteytab4").removeClass("this");
   });
   $("#goteytab3").mouseover(function(){
		
		$("#case1").hide();
		$("#case2").hide();
		$("#case3").show(); 
		$("#case4").hide();
		$("#goteytab1").removeClass("this");
		$("#goteytab2").removeClass("this");
		$("#goteytab3").addClass("this");
		$("#goteytab4").removeClass("this");
   });
   $("#goteytab4").mouseover(function(){
		
		$("#case1").hide();
		$("#case2").hide();
		$("#case3").hide();
		$("#case4").show(); 
		$("#goteytab1").removeClass("this");
		$("#goteytab2").removeClass("this");
		$("#goteytab3").removeClass("this");
		$("#goteytab4").addClass("this");
   });
   $.fn.s3Slider = function(vars) {       
        
        var element     = this;
        var timeOut     = (vars.timeOut != undefined) ? vars.timeOut : 4000;
        var current     = null;
        var timeOutFn   = null;
        var faderStat   = true;
        var mOver       = false;
        var items       = $("#" + element[0].id + "Content ." + element[0].id + "Image");
        var itemsSpan   = $("#" + element[0].id + "Content ." + element[0].id + "Image span");
            
        items.each(function(i) {
    
            $(items[i]).mouseover(function() {
               mOver = true;
            });
            
            $(items[i]).mouseout(function() {
                mOver   = false;
                fadeElement(true);
            });
            
        });
        
        var fadeElement = function(isMouseOut) {
            var thisTimeOut = (isMouseOut) ? (timeOut/2) : timeOut;
            thisTimeOut = (faderStat) ? 10 : thisTimeOut;
            if(items.length > 0) {
                timeOutFn = setTimeout(makeSlider, thisTimeOut);
            } else {
                console.log("Poof..");
            }
        }
        
        var makeSlider = function() {
            current = (current != null) ? current : items[(items.length-1)];
            var currNo      = jQuery.inArray(current, items) + 1
            currNo = (currNo == items.length) ? 0 : (currNo - 1);
            var newMargin   = $(element).width() * currNo;
            if(faderStat == true) {
                if(!mOver) {
                    $(items[currNo]).fadeIn((timeOut/6), function() {
                        if($(itemsSpan[currNo]).css('bottom') == 0) {
                            $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                                faderStat = false;
                                current = items[currNo];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        } else {
                            $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                                faderStat = false;
                                current = items[currNo];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        }
                    });
                }
            } else {
                if(!mOver) {
                    if($(itemsSpan[currNo]).css('bottom') == 0) {
                        $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                            $(items[currNo]).fadeOut((timeOut/6), function() {
                                faderStat = true;
                                current = items[(currNo+1)];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        });
                    } else {
                        $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                        $(items[currNo]).fadeOut((timeOut/6), function() {
                                faderStat = true;
                                current = items[(currNo+1)];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        });
                    }
                }
            }
        }
        
        makeSlider();

    };  
	$(document).ready(function() {
        $('#slider').s3Slider({
            timeOut: 4000
        });
    });
})


