$(document).ready(function()
{
	//Examples of how to assign the ColorBox event to elements
	$("a[rel='gallery']").colorbox({transition:"none", height:"80%"});
	$("a[class='forgot-pass']").colorbox({innerWidth:"535px", innerHeight:"400px", iframe:true});
    $('#slider').loopitems();

    // styles for targeting Safari only).
    var userAgent = navigator.userAgent.toString().toLowerCase();
    if ((userAgent.indexOf('safari') != -1) && !(userAgent.indexOf('chrome') != -1)) {
        $("footer li").css("margin-left","10px");
        $("footer li").css("margin-right","10px");
        $("footer  p .phone").css("margin-left","120px");
    }
});



/* ------------------ WHITE TRINANGLE IN DROP MENU ------------------ */
$("nav > ul > li").hover
(
    function ()
    {
        var liWidth = $(this).innerWidth();
       	$("nav span").css('width', liWidth);
        
        if ($.browser.msie)
        {
            if ( parseInt($.browser.version, 10) < 8 )
            {
       	        $("nav ul li span").css('margin-left', -liWidth);
            }
        }
    }
);



/* ------------------ SLIDER ------------------ */
(function($)
{
    var LoopItems = function(element,options)
  {
        var iiWrapper   = $('.item',element);
        var navWrapper  = $('.navigation',element);
                        
        var iiCurent    = 1
        var iiCount     = iiWrapper.size();

        // Show first item and activate first page navigation
        iiWrapper.filter(':first').show().addClass('cur-itm');
        $('ul li:first',navWrapper).addClass('active');
        
        // Merge options with defaults  
        var settings = $.extend({  
            duration: '7000'
        }, options || {});
                
        // Run slide show
        var iiInterval = setInterval("var loopitems = $('#"+element.attr('id')+"').data('loopitems'); loopitems.loopRun();",settings.duration);                     
                
        // Set navigation buttons onclick
        $('ul li a',navWrapper).click(function () 
        {       
            var loopitems = $('#'+$(this).parents('.loop').attr('id')).data('loopitems');
            clearInterval(iiInterval);
            loopitems.loopGoTo(this);
            return false;
        });         

        this.loopAnimate = function(nex)
        {
            iiWrapper.filter('.cur-itm').fadeOut(800);
            iiWrapper.filter(nex).addClass('cur-itm').fadeIn(1600);                             
        };
    
        this.loopRun = function()
        {                       
            iiCurent++;
            iiCurent = iiCurent > iiCount ? 1 : iiCurent;
            
            this.loopAnimate('#ii'+iiCurent);
        
            // Update navigation buttons
            $('ul li',navWrapper).removeClass('active');
            $('ul li a#p'+iiCurent,navWrapper).parent().addClass('active');                                                                           
        };    
        
        this.loopGoTo = function(obj)
        {                       
            if (obj.parentNode.className.indexOf('active') == -1) 
            {
                this.loopAnimate(obj.hash);                             
                $('ul li',navWrapper).removeClass('active');
                $(obj).parent().addClass('active');
            }
        };      
    };

    $.fn.loopitems = function(options)
    {
        return this.each(function()
        {                        
            var element = $(this);
            if (element.data('loopitems')) return; // Return early if this element already has a loopitems instance                                     
            
            element.addClass('loop');
            var loopitems = new LoopItems(element,options);
            element.data('loopitems', loopitems);  // Store plugin object in this element's data  
        });
    };
})(jQuery);

