﻿///<reference path="js/jqueryIntellisense.js"/>  
var activeBlock;
var lastBlock;
var isActive;

function setCurrent() {
    if (!isActive) {
        if ($(activeBlock) !== $(lastBlock)) {
            $(lastBlock).animate({ width: minWidth + "px" }, { queue: false, duration: 400 });
            $(activeBlock).animate({ width: maxWidth + "px" }, { queue: false, duration: 400 });
            lastBlock = activeBlock;
        }
        isActive = true;
    }
    else {
        isActive = false;
    }

}



function checkRollout() {
    //button has been rolled out of
    isActive = false;

    //test again to see if another button was rolled over
    setTimeout("pauseRoll()", 1000)

}

function checkRollover() {
    //button has been rolled over, and not button should be set back of
    isActive = true;
}

function pauseRoll() {
    //if nothign was rolled over, set them back
    if (!isActive) {
        setTimeout("setCurrent()", 2500);
    }

}
//swfobject
var so;

var currentImage;
var currentActive = 1;
var currImageName;

var currentState;



function updateNav(val) {

    if (val !== currentState) {
        clearWorkDiv();
        switch (val) {
            case "home":
                activeBlock = $('#a1');
                currImageName = '<img id="image" src="images/home_main_Bg.gif" style="width:651px;height:400px"/>';
                
                break;
            case "about":
                activeBlock = $('#a2');
                currImageName = '<img id="image" src="images/about_main_Bg.gif" style="width:651px;height:400px"/>';
                break;
            case "work":
                activeBlock = $('#a3');
                currImageName = '<img id="image" src="images/work_main_Bg.gif" style="width:651px;height:400px"/>';

                break;
            case "contact":
                activeBlock = $('#a4');
                currImageName = '<img id="image" src="images/contact_main_Bg.gif" style="width:651px;height:400px"/>';

                break;
            case "news":
                activeBlock = $('#a5');
                currImageName = '<img id="image" src="images/news_main_Bg.gif" style="width:651px;height:400px"/>';

                break;
            default:
                activeBlock = $('#a1');
                val = "home";
                currImageName = '<img id="image" src="images/home_main_Bg.gif" style="width:651px;height:400px"/>';

        }
        //START NEEW CODE

        if (currentActive == 1) {
            $(currentImage).fadeOut();
            currentImage = $("#Div2");
            currentActive = 2;
        }
        else {
            $(currentImage).fadeOut();
            currentImage = $("#Div1");
            currentActive = 1;
        }

        //update the new value
        $(currentImage).html(currImageName);
        $(currentImage).fadeIn('slow');


        //END NEW CODE
        $(lastBlock).animate({ width: minWidth + "px" }, { queue: false, duration: 400 });
        activeBlock.animate({ width: maxWidth + "px" }, { queue: false, duration: 400 });
        lastBlock = activeBlock;

        JStransition(val);

    }
    currentState = val;

}


function JStransition(val) {
    var obj = swfobject.getObjectById("flashCell");
    try {
        obj.JStransition(val);
    }
    catch (ex) {
        //could be nothing 
    }
}


//function to update the text, 

//need to get the repeater going for the News, possibly using ajax data controls

//need to update title, and background images

//----------->>

//define navigation 
jQuery(function($) {
    /**
    * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
    * @see http://flesler.demos.com/jquery/scrollTo/
    * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
    */

    /**
    * Restart the scroll position to ( 0, 0 ) (Firefox doesn't reset it)
    * could use $(target).scrollTo( 0, {axis:'xy'));
    * but this needs to be quick(synchronous), to reset before $.localScroll.hash() begins
    */
    $('#content').attr({ scrollTop: 0, scrollLeft: 0 });

    // Scroll initially if there's a hash (#something) in the url 
    $.localScroll.hash({
        target: '#content', //could be a selector or a jQuery object too.
        axis: 'yx', //the default is 'y'
        queue: true,
        duration: 1500
    });


    var $last = $([]); //save the last link

    /**
    * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
    * also affect the >> and << links. I want every link in the page to scroll.
    */
    $('#nav,.section,ul#ulnews').localScroll({
        target: '#content', //could be a selector or a jQuery object too.
        axis: 'yx', //the default is 'y'
        queue: true,
        duration: 1000,
        hash: false,

        onBefore: function(e, anchor, $target) {//'this' is the clicked link
            $last.removeClass('scrolling');
            $last = $(this).addClass('scrolling');
            if (this.blur)
                this.blur(); //remove the awful outline
        },
        onAfter: function(anchor) {
            $last.removeClass('scrolling');
        }
    });
});
//----------->>


//array used to preload the images
var preloadImgs = new Array();
preloadImgs[0] = "images/home_main_Bg.gif";
preloadImgs[1] = "images/about_main_Bg.gif";
preloadImgs[2] = "images/work_main_Bg.gif";
preloadImgs[3] = "images/contact_main_Bg.gif";
preloadImgs[4] = "images/news_main_Bg.gif";
preloadImgs[5] = "loader.gif";

$(document).ready(function() {
    lastBlock = $("#a1");
    maxWidth = 135;
    minWidth = 20;

    //initiate first sequence 
    if ($(activeBlock) !== $(lastBlock)) {
        activeBlock = $(lastBlock);
    }
    $(lastBlock).animate({ width: maxWidth + "px" });
    $("ul#nav li a").bind('mouseover',
    function() {
        $(lastBlock).animate({ width: minWidth + "px" }, { queue: false, duration: 400 });
        $(this).animate({ width: maxWidth + "px" }, { queue: false, duration: 400 });
        lastBlock = this;
    }
    );




    preloadImages(preloadImgs);
    updateNav('home');



});

function launchSite(site) {

    var newwin = window.open(site, "newwin", 'left=100,top=100,toolbar=no,status=no');

}

function showWork(id) {

    var url = "sites/";

    url = url + id;

    //load the ajax into the correct panel
    $('#work2Content').css('display', 'block').css('background', 'url(sites/images/loader.gif) 100px 100px no-repeat').load(url, function() {
        $('#work2Content').css('background', '');
        $('#work2contentDiv').css('display', 'block');
    });
}

///Hide the stuff that was loaded
function clearWorkDiv() {
    $('#work2Content').fadeOut(function() {
        $(this).html('')
    });
    $('#work2contentDiv').css('display', 'none');
}




function preloadImages(array)
{
    var i = 0;
    if (array.length > 0) 
    {
        $.each(array, function() {
            var img = new Image();
            try
            {
            $(img).attr('src', array[i]);
           
            }
            catch(ex)
            {
            alert('error');
            //do nothing, but dont freak out
            }
            i++;
            
        });
    }
} 

        
