
function init() {
	
	
	//**  INDEX  BINDS **//
	
 	$('a#chid-logo-index').click(function () {
		index_to_main('portfolio');
		// nullify normal click on a href
		return false; 	
	});
	
	$('div#indexImg').click(function () {
		index_to_main('portfolio');
		// nullify normal click on a href
		return false; 	
	});
	
	$('a#portfolio-index').click(function () {
		index_to_main('portfolio');
		// nullify normal click on a href
		return false; 
	});
	
	$('a#services-index').click(function () {
		index_to_main('services');
	
		// nullify normal click on a href
		return false;
	});
	 
	$('a#bio-index').click(function () {
		index_to_main('bio');
		// nullify normal click on a href
		return false;	
	});
	
	$('a#press-index').click(function () {
		index_to_main('press');
		
		// nullify normal click on a href
		return false;	
	}); 
	
	$('a#contact-index').click(function () {
		index_to_main('contact');
	
		// nullify normal click on a href
		return false;	
	});
	
	
	//** INDEX SLIDESHOW  **//
	
	var $ss = $('.IndexSlideshow');         
    
    // add slides to slideshow  
    for (var i = 2; i <= 6; i++) { 
		// jQuery.log("preloading slide " + i);
		$ss.append('<img src="/img/slideshow_911x607_' + i + '.jpg" width="911" height="607" />');  
 	}
 	
    // start the slideshow  
	// jQuery.log("ss.cycle start");
	
	$ss.cycle({
 
		fx: 'custom', 
		sync: 1,
		continuous: 1,
		pause: 1,
		speedIn: 19000,
		speedOut: 19000,
		delay: 5000, 
//		easeout: 'easeInOutCubic',
//		easein: 'easeInOutCubic',
//		easing: 'easeInOutCubic',
 		easing: 'easeInOutSine',
  		
 	    cssFirst:{  
	        left: 0,   
	        top:  0,  
	        display: 'block',
			opacity: 1.0,
	        'z-index': 3 
	    },   	
	    
 	    cssBefore:{  
	        left: 1100,   
	        top:  0,  
	        display: 'block',
			opacity: 1.0,
	        'z-index': 3 
	    }, 
	     
	    animIn: {  
	        top:  0,
	        left: 0,   
			opacity: 1.0
	    }, 
	    
	    animOut: {  
  	        top: 0,
	        left: -915, 
			opacity: 1.0

	    }, 
	    
 	    cssAfter:{  
	        display: 'none',
	        'z-index': 0
	    } 


	});
}




$(document).ready(function() {

	init(); 

});





//**  FUNCTIONS  **//


function initCatNav () {

	$("div#catNav").animate({		
		height: '125px'
		}, 
		0
	);
	
	
	$("a#chid-logo-main").click(function () {
		main_to_index();
		// jQuery.log("main_to_index");	
		return false; 	
	});	
			
			
	$("a#portfolio-link").click(function () {
		show_page('portfolio', false);
		return false;
	});

	
	$("a#services-link").click(function () {		
		show_page('services', false);
		return false;
	});

	$("a#bio-link").click(function () {		
		show_page('bio', false);
		return false;
	});

	$("a#press-link").click(function () {		
		show_page('press', false);
		return false;
	});

	$("a#contact-link").click(function () {		
		show_page('contact', false);
		return false;
	});

}

function show_page(page, fadein_menu) {

	// jQuery.log("show_page " + page);

 	$('div#content').animate({		
			opacity: '0.00'
			}, 
			500, 
			'easeInOutCubic',
			
			// callback
			function() {
			
				if (page == 'index_menu_only') { 	
					$('div#catNav').html(null); 
				}
				
				$.ajax({
				  url: page,
				  context: document.body,
				  success: function(html){
				//		$('div#content').append(html);
						$('div#content')
						.html(html)
						.animate({		
							opacity: '1.00'
							}, 
							500, 
							'easeInOutCubic',
							
							function() {
								// jQuery.log("page load success:  " + page);
								if (page == 'index_menu_only') { 
									init(); 
								}
								if (page == 'portfolio') {
									portfolio_slideshow();
								}
							}
						)
					}
				}); 
			
			}			
	);	 
 
	nav_width_each = 131;
	nav_width_offset = 675;

	// jQuery.log('div#mainTable width ' + $('div#mainTable').position().width )

	switch (page) {
		case 'portfolio': 	yellow_pos = nav_width_offset - (nav_width_each * 1); break;
		case 'services': 	yellow_pos = nav_width_offset - (nav_width_each * 2); break;
		case 'bio': 		yellow_pos = nav_width_offset - (nav_width_each * 3); break;
		case 'press': 		yellow_pos = nav_width_offset - (nav_width_each * 4); break;
		case 'contact': 	yellow_pos = nav_width_offset - (nav_width_each * 5); break; 
		default: 			yellow_pos = 0; break;
	}

	if (fadein_menu != 'nomenu')
	{	

		if (fadein_menu == true) 
		{	
		   	// jQuery.log("yellow to pos " + yellow_pos);
		   	// jQuery.log("fade in yellow");
			
			$("p#yellow_fade")
			.animate({		
				right:	yellow_pos
				}, 0, 'easeInOutCubic'	
			)		
			.animate({		
				opacity: '1.00'
				}, 750, 'easeInOutCubic'	
			);		
		}
		else {
			// jQuery.log("yellow to pos " + yellow_pos);

			$("p#yellow_fade")
			.animate({		
				right:	yellow_pos
				}, 750, 'easeInOutCubic'	
			);		
		
		} 
		
	}		 


}


function index_to_main(then_showPage)
{
	var l_index = $("a#chid-logo-index");
	var logo_index = l_index.position();
	// jQuery.log("logo_index right: " + logo_index.right + " logo_index left: " + logo_index.left + ", top: " + logo_index.top);
		
 	var logo_main = $("a#chid-logo-main").position();
	// jQuery.log("logo_main right: " + logo_main.right + " logo_main left: " + logo_main.left + ", top: " + logo_main.top);
		
  	
	$("div#indexNav").animate({
		  opacity:	'0.00'
		}, 
		2000, 
		'easeInOutCubic',
		
			/* callback on the longest animation */
		
			function() {
				
				$('div#content').html(null); 
			
				$.ajax({
				  url: 'catNav_div',
				  context: document.body,
				  success: function(html){
						$('div#catNav')
						.html(html)
						.animate({		
							opacity: '1.00'
							}, 
							1000, 
							'easeInOutCubic',
							
							function() {
								initCatNav();
								show_page(then_showPage, true);	
								// jQuery.log("show_page " + then_showPage);
							}
					)
				}
			}); 
				
		}
	);		
		
	$("div#slideContainer").animate({		
	    opacity: '0.00'
		}, 1000, 'easeInOutCubic' 
	);	
	
	$('.IndexSlideshow').delay(1000).cycle('stop');

	$("a#chid-logo-index img").animate({
		left: '-95px',
	//	top:  (logo_main.top)-parseFloat('105'),
		top:  -20,
		width:   	'148px',
		height:   	'92px'
		}, 2000, 'easeInOutCubic' 
	);	 
	
	$("a#portfolio-index img").animate({		
 		right: 		'-94px',
 		top:		'-75px', 
	 //   opacity:	'0.00',
		width:   	'143',
		height:   	'32'
		}, 2000, 'easeInOutCubic' 
	);	
		
	$("a#services-index img").animate({		
 		right: 		'-223px',
 		top:		'-143px', 
	  //  opacity:	'0.00',
		width:   	'143',
		height:   	'32'
		}, 2000, 'easeInOutCubic' 
	);	
	
	$("a#bio-index img").animate({		
 		right: 		'-352px',
 		top:		'-211px', 
	  //  opacity:	'0.00',
		width:   	'143',
		height:   	'32'
		}, 2000, 'easeInOutCubic' 
	);	
		
	$("a#press-index img").animate({		
 		right: 		'-480px',
 		top:		'-280px', 
	  //  opacity:	'0.00',
		width:   	'143',
		height:   	'32'
		}, 2000, 'easeInOutCubic' 
	);	
		
	$("a#contact-index img").animate({		
 		right: 		'-607px',
 		top:		'-347px',
	  //  opacity:	'0.00',
		width:   	'143',
		height:   	'32'
		}, 2000, 'easeInOutCubic' 
	);	 
	  
	  
	 	
	/* hack for IE */
 	/*  end hack for IE */
	
	
	
	/*
	$("div#catNav").delay(1000).animate({		
 		opacity: 1.00 
		}, 
		2000, 
		'easeInOutCubic',
		
		// callback on the longest animation 
		function() {
		
			show_page(then_showPage, true);	
		
		}
	);	
	*/
	
	

	
  	
}


function main_to_index()
{
	var l_index = $("img#chid-logo-index");
	var logo_index = l_index.position();
//	// jQuery.log("logo_index right: " + logo_index.right + " logo_index left: " + logo_index.left + ", top: " + logo_index.top);
		
 	var logo_main = $("p#chid-logo").position();
//	// jQuery.log("logo_main right: " + logo_main.right + " logo_main left: " + logo_main.left + ", top: " + logo_main.top);
	
   	
	$("div#indexNav").animate({
		  opacity:	'1.00'
		}, 1500, 'easeInOutCubic' 
	);	
	
	
	$("div#slideContainer").animate({		
	    opacity: '1.00'
		}, 1500, 'easeInOutCubic' 
	);	
	
	
	$("a#chid-logo-index img").animate({
		left: '0',
		top:  '0',
	 	width:   	'222px',
	 	height:   	'132px',
	    opacity:	'1.00'
		}, 
		750, 'easeInOutCubic' 
	);	 	
	
	$("a#portfolio-index img").animate({		
 		right: 		'0',
 		top:		'0', 
	    opacity:	'1.00',
		width:   	'214',
		height:   	'48'
		}, 
		750, 'easeInOutCubic' 
	);			
	
	$("a#services-index img").animate({		
 		right: 		'0',
 		top:		'0', 
 		opacity:	'1.00',
		width:   	'214',
		height:   	'48'
		},
		750, 'easeInOutCubic' 
	);	
	
	$("a#bio-index img").animate({		
 		right: 		'0',
 		top:		'0', 
 		opacity:	'1.00',
		width:   	'214',
		height:   	'48'
		}, 750, 'easeInOutCubic' 
	);	
		
	$("a#press-index img").animate({		
  		right: 		'0',
 		top:		'0', 
 		opacity:	'1.00',
		width:   	'214',
		height:   	'48'
		}, 750, 'easeInOutCubic' 
	);	
		
	$("a#contact-index img").animate({		
 	 	right: 		'0',
 		top:		'0', 
 		opacity:	'1.00',
		width:   	'214',
		height:   	'48'
		}, 750, 'easeInOutCubic' 
	);	 
	
	$("div#slideContainer").animate({		
	    opacity: '1.00'
		}, 1500, 'easeInOutCubic' 
	);			

	
	$("div#catNav").animate({		
 		opacity: '0.00' 
		}, 1250, 'easeInOutCubic'
	);	
	
	
	$("p#yellow_fade")
	.animate({		
		opacity: '0.00'
		},
		1250,
		'easeInOutCubic',		
		
		// callback on the longest animation 
		function() {
			
 			show_page('index_menu_only', 'nomenu');	
 			
					
			$("div#catNav").delay(500).animate({		
				height: '0px'
				}, 
				0
			);
	
 		}			

	);			

	
 	return true;

}


function portfolio_slideshow()
{
    	
    // start the slideshow  
	jQuery.log("ps.cycle start");
	
	$('.portfolio_slideshow')    
	.before('<div id="portfolio_ui">') 
	.cycle({ 
	    fx:     'custom', 
	    speed:  1200, 
		easing: 'easeInOutSine',
	    sync:	1,
	    cssFirst:{
	    	opacity:1.0
	    },
	    animIn:{
	        top:  0,
	        left: 0,   
			opacity: 1.0
	    },
	    animOut: {  
  	        top: 0,
	        left: -1150, 
			opacity: 0.0 
	    }, 
	   	cssBefore:{  
	        left: 1150,   
	        top:  0,  
	        display: 'block',
			opacity: 0.0,
	        'z-index': 3 
	    }, 
 	    cssAfter:{  
	        display: 'none',
	        'z-index': 0
	    }, 
	    timeout: 0,
	    pager:  '#portfolio_ui'	    
	});
	
	
	// enable lightbox
	$('a.lb').lightbox();
	
		

}







/* old


$("a#portfolio-link").click(function () {
	
	var p = $(this);
	var portfolio = p.position();	
	// // jQuery.log("portfolio right: " + portfolio.right + " portfolio left: " + portfolio.left + ", top: " + portfolio.top);
		
	$("p#yellow_fade").animate({		
		right: (parseFloat('993') - portfolio.left)
		}, 750, 'easeInOutCubic'
		
	);		
 	return false;
});



$("a#services-link").click(function () {
  
 	var p = $(this);
	var services = p.position();	
	// jQuery.log("services left: " + services.left + ", top: " + services.top);
	
	$("p#yellow_fade").animate({
		right: (parseFloat('993') - services.left)
		}, 750, 'easeInOutCubic'
		
	);		
 	return false;
});




$("a#bio-link").click(function () {
  
 	var p = $(this);
	var bio = p.position();	
	// jQuery.log("bio left: " + bio.left + ", top: " + bio.top);
	
	$("p#yellow_fade").animate({
		right: (parseFloat('993') - bio.left)
		}, 750, 'easeInOutCubic'
		
	);		
 	return false;
});


 

$("a#contact-link").click(function () {
  
 	var p = $(this);
	var contact = p.position();	
	// jQuery.log("contact left: " + contact.left + ", top: " + contact.top);
	
	$("p#yellow_fade").animate({
		right: (parseFloat('993') - contact.left)
		}, 750, 'easeInOutCubic'
		
	);		
 	return false;
});




$("a#press-link").click(function () {
  
 	var p = $(this);
	var press = p.position();	
	// jQuery.log("press left: " + press.left + ", top: " + press.top);
	
	$("p#yellow_fade").animate({
		right: (parseFloat('993') - press.left)
		}, 750, 'easeInOutCubic'
		
	);		
 	return false;
});




$("div#catNav").click(function () {

	var p = $(this);
	var position = p.position();
	
 // jQuery.log("catNav left: " + position.left + ", top: " + position.top);

 return false;
 
});


*/


$.Lightbox.construct({
       "show_linkback":    false,
       "show_info": true,
       "show_extended_info": true,
       "download_link": false,

        "text": {

            // For translating
            "image":        "Image",
            "of":           "of",
            "close":        "Close X",
            "closeInfo":    "You can also click anywhere outside the image to close.",
            "download":     "Download.",
            "help": {
                "close":    "Click to close",
                "interact": "Hover to interact"
            },
            "about": {
                "text":     "jQuery Lightbox Plugin (balupton edition)",
                "title":    "Licenced under the GNU Affero General Public License.",
                "link":     "http://www.balupton.com/projects/jquery-lightbox"
            }
        }
    });


/**
 * Copyright (C) 2009 Jonathan Azoff <jon@azoffdesign.com>
 *
 * This script is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 *
 * // jQuery.log v1.0.0 - A jQuery plugin that unifies native console logging across browsers
 * 
 * @usage		call // jQuery.log([args...]) to write to attempt to write to the console of any browser. 
 *				**See http: *azoffdesign.com/plugins/js/log for an example.
 * @param 		args...	one or more javascript objects to be written to the console
 * @returns 	true if a console was detected and successfully used, false if the plug-in had to resort to alert boxes
 * @note 		if a plug-in cannot be located then an alert is called with the arguments you wish to log. Multiple 
 *              arguments are separated with a space.
 * @depends 	just make sure you have jQuery and some code you want to debug.
 */
(function($){
	$.extend({"log":function(){ 
		if(arguments.length > 0) {
			
			// join for graceful degregation
			var args = (arguments.length > 1) ? Array.prototype.join.call(arguments, " ") : arguments[0];
			
			// this is the standard; firebug and newer webkit browsers support this
			try { 
				console.log(args);
				return true;
			} catch(e) {		
				// newer opera browsers support posting erros to their consoles
				try { 
					opera.postError(args); 
					return true;
				} catch(e) { }
			}
			
			// catch all; a good old alert box
			alert(args);
			return false;
		}
	}});
})(jQuery);





/* 
	IE PNG fix multiple filters 
	http://stackoverflow.com/questions/1156985/jquery-cycle-ie7-transparent-png-problem
*/
(function ($) {
    if (!$) return;
    $.fn.extend({
        fixPNG: function(sizingMethod, forceBG) {
                if (!($.browser.msie)) return this;
                var emptyimg = "/nav/empty.gif"; //Path to empty 1x1px GIF goes here
                sizingMethod = sizingMethod || "scale"; //sizingMethod, defaults to scale (matches image dimensions)
                this.each(function() {
                        var isImg = (forceBG) ? false : jQuery.nodeName(this, "img"),
                                imgname = (isImg) ? this.src : this.currentStyle.backgroundImage,
                                src = (isImg) ? imgname : imgname.substring(5,imgname.length-2);
                        this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + sizingMethod + "')";
                        if (isImg) this.src = emptyimg;
                        else this.style.backgroundImage = "url(" + emptyimg + ")";
                });
                return this;
        }
    });
})(jQuery);




 
