$(document).ready(function() {
	banner();
	easy_slider();
	engage();
	minor();
	social_footer();
	switch_view();
	complete();
	hover_fade();
	side_tab();
	reveal();
	hide_img();	
	screen_width();
	general();
	logout();
});

function general() {
	$('.widget ul li:last-child').css('border-bottom','none');
	$('#equalise').equalHeights();
	$('.sf-menu > li').clone().appendTo('.f_mid ul');
	$('.f_mid li').children('ul').remove();
	$('.f_mid li').removeAttr('class');

}

function easy_slider() {
	$("#slider").easySlider({
		auto: true,
		continuous: true,
		speed: 1000,
		pause: 10000
	});
}

function banner() {
	$('#banner').nivoSlider({
		effect: 'slideInRight', // Specify sets like: 'fold,fade,sliceDown'
        animSpeed: 500, // Slide transition speed
        pauseTime: 10000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: true, // Next & Prev navigation
        directionNavHide: true, // Only show on hover
        controlNav: true, // 1,2,3... navigation
        controlNavThumbs: false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel: false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav: true, // Use left & right arrows
        pauseOnHover: true, // Stop animation while hovering
        manualAdvance: false, // Force manual transitions
        captionOpacity: 0.8, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded	
	});
}

//
function reveal(){
	$(".show_btn_orange").click(function () {
		$(".reveal").slideToggle("normal");
		$(this).toggleClass("active");
		return false;
	});
}
//
//
function hover_fade(){
	$("#latest_holder").show();
	$("#latest_holder img").fadeTo('normal', 1, function() {
			$(this).hover(function(){
				$(this).fadeTo('normal', 0.3);				
			}, function() {
					$(this).fadeTo('normal', 1);
			});		
    });
}
//
//
function side_tab(){
	$('.side_tab').hover(function () {
		$('.side_tab').animate({
			left: '-15px'
		}, 200);
	}, function () {
		$('.side_tab').animate({
			left: '-20px'
		}, 300);
	});
}
//
//
function switch_view(){
	$("a.switch_thumb").toggle(function(){
        $(this).addClass("swap");
        $("ul.grid").fadeOut("fast", function() {
			$(this).removeClass("grid");
            $(this).fadeIn("fast").addClass("list");
        });
    }, function () {
        $(this).removeClass("swap");
        $("ul.list").fadeOut("fast", function() {
			$(this).removeClass("list");
            $(this).fadeIn("fast").addClass("grid");
        });
    });
}
//
//
function engage(){
	$('#tabs').tabs({ fx: { opacity: 'toggle', height: 'toggle' } }); // make the tabs work
	$('ul.sf-menu').superfish({ 
        delay:       250                          // one second delay on mouseout 
	});
	$("a[rel^='prettyPhoto']").prettyPhoto(); // makes lightbox work
}
//
//
function social_footer(){
	$('.footer-widget .social-links a:has(img)').fadeTo("fast","0.7");
	$('.footer-widget .social-links a:has(img)').hover(function() {
		$(this).stop().fadeTo("fast","1");
		}, function() {
		$(this).stop().fadeTo("fast","0.7");
	});
}
//
//
function minor(){
	$('span.close').click(function() {
		$(this).parent().fadeOut(400);					   
	});
}
//
//
function complete(){
	$('ul.sf-menu').before('<div id="nav-finish"></div>');
	$('#pagename h2 span').after('<img src="/assets/images/pagename-right.png" alt="" id="pagename-finish" />');
}
//
//
function hide_img(){
	$('.port-box img').hide();//hide all the images on the page
}
//
//
var i = 0;//initialize
var int=0;//Internet Explorer Fix
$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
	var int = setInterval("preload(i)",300);//500 is the fade in speed in milliseconds
});

function preload(){
	var images = $('#content img').length;//count the number of images on the page
	if (i >= images) {// Loop the images
		//clearInterval(int);//When it reaches the last image the loop ends
	}
	$('#content img:hidden').eq(0).fadeIn(500);//fades in the hidden images one by one
	
	i++;//add 1 to the count
}
//
//

function screen_width() {
    if (screen.width<=1024) {
        $("#tab").css('display', 'none');
    }
}

function logout() {
	$('#logout').click(function() {	
		if (confirm("Are you sure you want to logout?")) {				
			$.ajax({
				type: "GET",
				url: "/login/authentication.php?action=logout",
				dataType: "json",
				success: function(json) {
					document.location = json.location;
				}
			});					
		}			
		return false;			
	});
}
