// JavaScript Document

$(document).ready(function() {
	
	//print copy rollovers
	$("#photo_large.7").hover(
        function () {
			$("#photo_large").attr("src","images/print/7_flip.jpg");
        },function(){
			$("#photo_large").attr("src","images/print/7.jpg");
	});
	
	$("#photo_large.4").hover(
        function () {
			$("#photo_large").attr("src","images/print/4_flip.jpg");
        },function(){
			$("#photo_large").attr("src","images/print/4.jpg");
	});
	
	//home page X rollovers
	$(".homeSection").css("background-image", "url(images/home_check.gif)");
	
	$("#homeColumn a").hover(
        function () {
			$(this).children('.homeSection').css("background-image", "url(images/home_checkX.gif)");
        },function(){
			$(this).children('.homeSection').css("background-image", "url(images/home_check.gif)");
	});
	
	//side menus arrows
	$(".portfolioCategory a").hover(
        function () {
			$(this).parents('.portfolioCategory').css("background-image", "url(images/leftNav_bgRO.gif)");
        },function(){
			$(this).parents('.portfolioCategory').css("background-image", "url(images/leftNav_bg.gif)");
	});
	
	
	//side menus arrows, keep writer lit up thru submenu nav ro
	$("#writer").hover(
        function () {
			$('.portfolioWriter').css("background-image", "url(images/leftNav_bgRO.gif)");
        },function(){
			$('.portfolioWriter').css("background-image", "url(images/leftNav_bg.gif)");
	});
	
	
	//side menus check box
	$(".portfolioCategorySub a").hover(
        function () {
			$(this).parents('.portfolioCategorySub').css("background-image", "url(images/checkboxX.gif)");
        },function(){
			$(this).parents('.portfolioCategorySub').css("background-image", "url(images/checkbox.gif)");
	});
	
	//centers portfolio and arrows within center column	
			$('#portfolioMiddle').hide();
			$('#portfolioMiddle').fadeIn('5000');
			var newPortfolioMiddle = $('#portfolioMiddle img').attr("width");
			$('#portfolioMiddle').css("width", newPortfolioMiddle);
			var newPortfolioWrapper = newPortfolioMiddle + 140;
			$('#portfolioWrapper').css("width", newPortfolioWrapper);

		
	//marks current portfolio page TN image and removes link
	var pathname = jQuery.url.attr("path");
	var curPage = pathname.slice(-6);
	$(".TNsections a[href*='" + curPage + "'] img").addClass('portfolioTNcurrent').removeClass('portfolioTN');
	$(".TNsections a[href*='" + curPage + "']").removeAttr("href");

	
	//right side menus arrows keep for current one
	$(".portfolioTNcurrent").parents('.TNsections').css("background-image", "url(images/rightNav_bgRO.gif)");	
	
	//right side menus arrows
	$(".portfolioTN").hover(
        function () {
			$(this).parents('.TNsections').css("background-image", "url(images/rightNav_bgRO.gif)");
			$(this).css("border-color", "#000");
        },function(){
			$(this).parents('.TNsections').css("background-image", "url(images/rightNav_bg.gif)");
			$(this).css("border-color", "#FFF");
	});
	
	
	//activates arrow links by using current url, slice the start of if for the section, the middle for the current number and then adding and 	substracting for previous and next
	var curSection = pathname.slice(0, -6);
	var nextNumber = +(curPage.slice(0, 1)) + 1;
	var nextArrow = curSection + nextNumber + ".html";
	var prevNumber = +(curPage.slice(0, 1)) - 1;
	var prevArrow = curSection + prevNumber + ".html";
	var lastNumber = $(".TNsections").get();
	
	if (prevNumber == 0) {
		$(".arrowL").css("visibility", "hidden");
		$(".arrowL a").removeAttr("href");
	}
	else {
		$(".arrowL a").attr({href: prevArrow});
	}
	
	if (nextNumber > lastNumber.length) {
		$(".arrowR").css("visibility", "hidden");
		$(".arrowR a").removeAttr("href");
	}
	else {
		$(".arrowR a").attr({href: nextArrow});
		
	}

});// document ready


// slideshow for online sections
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG: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}, 2000, function() {
            $active.removeClass('active last-active');
        });
}

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



