/*//////////////////////////////////////////////////////////////////////////////////////////////////////////
		CUSTOM JAVASCRIPT EFFECTS  
//////////////////////////////////////////////////////////////////////////////////////////////////////////*/


/****************************************************************************
	BANNER - Customising the home page banner 
****************************************************************************/


/****************************************************************************
	BANNER - Customising the home page banner 
****************************************************************************/

jQuery(function($) {
	
	var timer;
	var container = '#BANNER '; /* ID name of the DIV */
	var slides = 4; /* Number of slides */
	
	var i=1;
	var next;
	
	function button(id)
	{
		$(container+'ul.slides li').hide();
		$(container+'ul.slides li.slide'+id).fadeIn(500);
		$(container+'ul.buttons li').removeClass('active');
		$(container+'ul.buttons li.button'+id).addClass('active');
		
		if(id == slides){
  			next = 1;
  		}else{
  			next = parseInt(id)+1;
  		}
		
		clearTimeout(timer);
		timer = setTimeout(function(){
			$(container+'ul.slides li').fadeOut(1000);
			setTimeout(function(){
				button(next);
			}, 1000);
		}, 7000);
		
		
		return false;
	}
	
	function onLoad()
	{
		$(container+'ul.slides li').hide();
		$(container+'ul.slides li.slide1').fadeIn(500);
		$(container+'ul.buttons li.button1').addClass('active');
		
		clearTimeout(timer);
		timer = setTimeout(function(){
			$(container+'ul.slides li').fadeOut(1000);
			setTimeout(function(){
				button(2);
			}, 1000);
		}, 7000);
	}
	
	/* slide indicator buttons */
	while(i <= slides)
	{
		$(container+'.button'+i+' a').click(function(){
			var value = $(this).parent().attr("class").substr(6);
			button(value);
			return false;
		});
  		
		i++;
	}
  	
	onLoad();

});


/****************************************************************************
	SCROLL TO TOP
****************************************************************************/

$(function ()
{
    $.fn.scrollToTop = function (options)
    {
        if (options)
        {
            var speed = options.speed;
            var ease = options.ease;
        }
        else
        {
            var speed = "slow";
            var ease = "jswing";
        }
        var scrollDiv = $(this);
        $(this).hide().removeAttr("href");
        if ($(window).scrollTop() != "0")
        {
            $(this).fadeIn("slow");
        }
        $(window).scroll(function ()
        {
            if ($(window).scrollTop() == "0")
            {
                $(scrollDiv).fadeOut("slow");
            }
            else
            {
                $(scrollDiv).fadeIn("slow");
            }
        });
        $(this).click(function (event)
        {
            $("html, body").animate(
            {
               scrollTop: "0px"
            }, speed, ease);
        });
    }
}); 


/* --- ADDITIONAL CODE FOR 'SCROLL TO TOP' EFFECT --- */

$(function() {
	$(".toTop").scrollToTop({speed:1200,ease:"easeInOutCubic"});
});




/***************************************************
		TABS JAVASCRIPT
***************************************************/

jQuery(document).ready(function($){
	// PRODUCT switcher tabs
	$(".switch-content").hide(); //Hide all content
	$("ul.tab-switcher li:first").addClass("active").show(); //Activate first tab
	$(".switch-content:first").show(); //Show first tab content
	
	
	//On Click Event for PRODUCT Switcher
	$("ul.tab-switcher li").click(function() {
		$("ul.tab-switcher li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".switch-content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});	
	
	
	// IMAGE switcher tabs
	$(".switch-image").hide(); //Hide all content
	$("ul.image-switcher li:first").addClass("active").show(); //Activate first tab
	$(".switch-image:first").show(); //Show first tab content
	
	
	//On Click Event for IMAGE switcher
	$("ul.image-switcher li").click(function() {
		$("ul.image-switcher li").removeClass("active"); //Remove any "active" class		
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".switch-image").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

})


/***************************************************
		PDF PREVIEW FADE
***************************************************/

jQuery(document).ready(function($){
	$("a.pdf-preview").hover(
		function() {
		$(".pdfthumb").stop().animate({"opacity": "1"}, "medium");
		},
		function() {
		$(".pdfthumb").stop().animate({"opacity": "0"}, "medium");
	});
 
});



/***************************************************
		NEWS TICKER FADE
***************************************************/

$.fn.fadeystuff = function(options) {
    var defaultOptions = {
        childSelector: '.item',
        fadeSpeed: 1000,
        lingerTime: 8000
    }

    var o = $.merge(options, defaultOptions);

    var children = this.children(o.childSelector);
    $(children[0]).show();

    if (children.length > 1) {
        var current = $(children[0]);
        var infiniteLoopOfDeath = function() {
            current.fadeOut(o.fadeSpeed, function() {
                current = current.next();
                if (current.length === 0) {
                    current = $(children[0]);
                }

                current.fadeIn(o.fadeSpeed, function() {
                    setTimeout(infiniteLoopOfDeath, o.lingerTime);
                });
            });
        }

        setTimeout(infiniteLoopOfDeath, o.lingerTime);
    }
}

$(document).ready(function() {
    $('.items').fadeystuff({
        childSelector: '.item',
        fadeSpeed: 1000,
        lingerTime: 6000
    });
});




















