// requires jquery (slide, fadeto, animate, ajax) ui core, ui efects (for hex colour support)




$(document).ready(function(){ //Begin onLoad  
    FLIR.init( { path: 'core/facelift/' });
	$("h2").each( function() { FLIR.replace(this); } );
	$("h3").each( function() { FLIR.replace(this); } );
	$("h4").each( function() { FLIR.replace(this); } );


/*
	$('h2').sifr({path: 'core/', font: 'metror', color:'#365f91'});
	$('h3').sifr({path: 'core/', font: 'metror', color:'#365f91'});
	$('h3.white').sifr({path: 'core/', font: 'metror', color:'#ffffff'});
   	$('h4').sifr({path: 'core/', font: 'metror', color:'#284c6f'});
	$('h4.orange').sifr({path: 'core/', font: 'metror', color:'#8c391d'});
	$('h4.brown').sifr({path: 'core/', font: 'metror', color:'#83691c'});
	$('h4.dark').sifr({path: 'core/', font: 'metror', color:'#303037'});
	$('h4.lightblue').sifr({path: 'core/', font: 'metror', color:'#65a7c6'});
	$('h4.light').sifr({path: 'core/', font: 'metror', color:'#8f8f8f'});
	$('h4.blue').sifr({path: 'core/', font: 'metror', color:'#365f91'});

*/
   /*
 $('#contactTel div.center').corner();
	$('#emailForm div.center').corner("left");
    $('#emailForm div.right').corner("right");
*/
    
	$('.column-right .item').corner();
	
	// Get the panel prep'd
	$("div[id^=showcase2-]").hide();
	$('#showcase2-nav-website').addClass("active");
	$('#showcase2-website').fadeIn("slow");

	// listen out and activate the right panel
	$("a[id^=showcase2-nav-]").click(function () {
		$("a[id^=showcase2-nav-]").removeClass("active");
		var currentId = $(this).attr("id").substr(14);
		$(this).addClass("active");
		$("div[id^=showcase2-]").hide();
		$('#showcase2-'+currentId).fadeIn("slow");	
	});
   
   
   
    /* ---------- Login panel sliding ---------- */
    $('#loginPanel').hide();
    $('#toggleLogin').click(function(){
        $('#loginPanel').slideToggle();
    });
    $('#closeLogin').click(function(){
        $('#loginPanel').slideUp();
    });
    
    
    
    /* ---------- Protect contact details from robots ---------- */
    $('span.tel').html("<a href=\"contact\">01322 518 553</a>");
    $("span.email").html("<a href=\"mailto:contact@reeflogic.co.uk\">contact@reeflogic.co.uk</a>");
    $('span.skype').html("<a href=\"contact\">aarondja</a>");
    
    
    
    // ---------------- Image Hover Animation ---------------- //
    $("a.thickbox img").hover(function(){
        $(this).fadeTo("fast", 0.5);
    }, function(){
        $(this).fadeTo("fast", 1.0);
    });
    
    
    
    // ---------------- Navigation Animation ---------------- //
    $('#nav li a[class=active]').animate({
        backgroundColor: "#222",
        color: "#fff"
    }, 'slow');
    
    
    $('#nav li a[class=]').hover(function(){
        $(this).animate({
            backgroundColor: "#444347",
            color: "#fff"
        }, 'fast');
    }, function(){
        $(this).animate({
            backgroundColor: "#36353a",
            color: "#999899"
        }, 'fast');
    });
    
    
    
    
    
    
    // ---------------- Contact Form Animation ---------------- //
    $('#submitForm input').focus(function(){
        $(this).animate({
            backgroundColor: '#C1D5DC'
        }, 'fast');
    });
    $('#submitForm input').blur(function(){
        $(this).animate({
            backgroundColor: '#fff'
        }, 'fast');
    });
    
    $('#submitForm textarea').focus(function(){
        $(this).animate({
            backgroundColor: '#C1D5DC'
        }, 'fast');
    });
    $('#submitForm textarea').blur(function(){
        $(this).animate({
            backgroundColor: '#fff'
        }, 'fast');
    });
    
    
    
    /* ---------- Contact form ---------- */
    $("#submitForm").submit(function(){
        $('#output').html('<img alt="" src="layout/theme1/loading.gif" />');
        $.post('core/ajax-mail.php', {
            require: $('[name=require]').val(),
            name: $('[name=name]').val(),
            email: $('[name=email]').val(),
            telephone: $('[name=telephone]').val(),
            enquiry: $('[name=enquiry]').val(),
            message: $('[name=message]').val()
        }, function(data){
            $('#output').html(data).fadeIn();
        });
        return false;
    });
    
    
}); // End onLoad









/* ---------- Header transition ---------- */

function slideSwitch(){
    var $active = $('#headertransition div.active');
    
    if ($active.length == 0) 
        $active = $('#headertransition div:last');
    
    // use this to pull the images in the order they appear in the markup
    var $next = $active.next().length ? $active.next() : $('#headertransition div:first');
    
    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    
    
    $active.addClass('last-active');
    
    $next.css({
        opacity: 0.0
    }).addClass('active').animate({
        opacity: 1.0
    }, 1000, function(){
        $active.removeClass('active last-active');
    });
}

$(function(){
    setInterval("slideSwitch()", 5000);
});
    