
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	INIT sIFR
	================================================================================ */
	
		var smallcaps = { src: 'http://www.picastudio.com/swf/smallcaps.swf' };
		var roman = { src: 'http://www.picastudio.com/swf/roman.swf' };
		var italic = { src: 'http://www.picastudio.com/swf/italic.swf' };
		var bold = { src: 'http://www.picastudio.com/swf/bold.swf' };
		sIFR.activate(smallcaps, roman, italic, bold);
		
		
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	CALLED BY CYCLE PAGER
	================================================================================ */	
	
		function onAfter(curr, next, opts) {
			var index = opts.currSlide;
				if (index == 0 ) {
					//$('#prev').css("display","none");
					$('#prev').attr('class', 'disabled');
				} else {
					//$('#prev').css("display","inline");
					$('#prev').attr('class', 'enabled');
				}
					if (index == opts.slideCount - 1) {
						//$('#next').css("display","none");
						$('#next').attr('class', 'disabled');
					} else {
						//$('#next').css("display","inline");
						$('#next').attr('class', 'enabled');
					}
						/*$('#pageNum').html( '<span style="color:#F00;"> ' + (opts.currSlide +1) + '</span> / ' + opts.slideCount );*/
		}
		
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	PAGE LOADED
	================================================================================ */
	

$(document).ready(function() {
						   			   
		//$.preloadCssImages();
		
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	HOMEPAGE jCAROUSEL
	================================================================================ */
		
		if ( $('body').attr('id') == 'home') {
			 jQuery('#carousel').jcarousel({
				scroll: 1
			}); 
		}
		

/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	sIFR CONFIG
	================================================================================ */
	
		sIFR.replace(smallcaps, {
		  selector: 'h3'
		 ,wmode: 'transparent'
		 ,offsetTop: -10
		 ,tuneHeight: -17
		  ,css: '.sIFR-root { color: #FFFFFF; }'
		});
		
		if ( $('body').attr('id') != 'home') {
			sIFR.replace(smallcaps, {
			  selector: 'h4'
			 ,wmode: 'transparent'
			 ,offsetTop: -6
			 ,tuneHeight: -6
			  ,css: '.sIFR-root { color: #FFFFFF; }'
			  ,onRelease: function(fi) { toggleFlash(fi) }
			});
		} else {
			sIFR.replace(smallcaps, {
			  selector: 'h4'
			 ,wmode: 'transparent'
			 ,offsetTop: -6
			 ,tuneHeight: -6
			  ,css: '.sIFR-root { color: #FFFFFF; }'
			});
		}
		
		sIFR.replace(smallcaps, {
		  selector: 'h5'
		 ,wmode: 'transparent'
		 ,offsetTop: -4
		 ,tuneHeight: -4
		  ,css: '.sIFR-root { color: #FFFFFF; }'
		  ,onRelease: function(fi) { toggleFlash(fi) }
		});
		
		sIFR.replace(italic, {
		  selector: '.caption p'
		  ,wmode: 'transparent'
		 ,tuneHeight: 2
		  ,css: '.sIFR-root { leading:6; color: #FFFFFF; }'
		});
		
		
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	TIPSY TOOLTIPS
	================================================================================ */
		
		$('.tip-n').tipsy({ gravity: 'n', fade: true });
		$('.tip-s').tipsy({ gravity: 's', fade: true });
		$('.tip-e').tipsy({ gravity: 'e', fade: true });
		$('.tip-w').tipsy({ gravity: 'w', fade: true });
		
		$('.toggle_open, .toggle_close').tipsy({ gravity: 's', fade: true });
		
		
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	TOP ARCHIVE
	================================================================================ */
	
	
		$('#archiveBtn').click(function (event) {
			event.preventDefault();
				if ($(this).attr('class') == 'down') {
					$(this).attr('class', 'up');
				} else if ($(this).attr('class') == 'up') {
					$(this).attr('class', 'down');
				}
			animatedcollapse.toggle("archive");
		});
		
		animatedcollapse.addDiv( "archive" , 'fade=1, hide=1');
		
		
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	WORK MENU FILTERS
	================================================================================ */	
		
		
		$('.menuset').each(function() {		  
				animatedcollapse.addDiv( $(this).attr("id") , 'fade=1, hide=1, group=one');
		});
		
		
		$('#menu_header li#date_header a, #menu_header li#category_header a, #menu_header li#typeface_header a').each(function() {
				
				$(this).click(function (event) {
					event.preventDefault();
					toggleMenu( $(event.target).attr("rel") );
				});						 
				
		});
		
		function toggleMenu( targetDiv ) {
			
			animatedcollapse.toggle( targetDiv );
			
			$('#menu_header li a.menu_open, #menu_header li a.menu_close').each(function() {						 
				if ( $(this).attr('rel') != targetDiv) {
					 $(this).attr('class', 'menu_open');
				} else {
					
					if ($(this).attr('class') == 'menu_open') {
						$(this).attr('class', 'menu_close');
					} else if ($(this).attr('class') == 'menu_close') {
						$(this).attr('class', 'menu_open');
					}
				}
			});								 		
		}
		
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	WORK MENU TOGGLE LIST VS GRID PRESENTATION
	================================================================================ */	
	
		$('a.list_on, a.grid_off, a.list_off, a.grid_on').each(function() {
			$(this).click(function (event) {
					event.preventDefault();															
					if ($(this).attr('class') == 'list_off' || $(this).attr('class') == 'list_on') {															
						$('#grid').attr('id', 'list');
						$('a.list_off').attr('class', 'list_on');
						$('a.grid_on').attr('class', 'grid_off');
						// imgs don't disappear in ie 6 or 7
						$('.imgs, .tip-s').each(function() {
							$(this).hide();
						});
						
					} else if ($(this).attr('class') == 'grid_off' || $(this).attr('class') == 'grid_on') {
						$('#list').attr('id', 'grid');
						$('a.list_on').attr('class', 'list_off');
						$('a.grid_off').attr('class', 'grid_on');
						
						// imgs don't disappear in ie 6 or 7
						$('.imgs, .tip-s').each(function() {
							$(this).show();
						});
					}
			});	
			
		});	
		
		
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	WORK MENU FILTER PROJECTS LIST
	================================================================================ */	
	
	$('ul.menuset li a').each(function() {
									   
		$(this).click(function (event) {
			event.preventDefault();
			var filterBy = $(event.target).attr('rel');
			
			$('.project').each(function() {
				hasFilter = $(this).attr('rel').indexOf(filterBy);
					if (hasFilter == -1) {
						$(this).fadeTo("fast", 0.5);
					} else {
						$(this).fadeTo("fast", 1);
					}							   							   
			});						
		});	
	});	
	
	
		
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	TOGGLE CONTENT
	================================================================================ */
	
		$('.toggle_open, .toggle_close').click(function (event) {
			event.preventDefault();
			toggleMe( $(event.target).parent().parent().children('.toggle_content') );
				
		});
		
		
		$('.toggle_open').each(function() {		  
				closeMe( $(this).parent().parent().children('.toggle_content') );
		});
		
		
		$('.toggle_close').each(function() {		  
				initMe( $(this).parent().parent().children('.toggle_content') );
		});
		
		
		
		function toggleFlash(fi) {
			var h = fi.getAncestor();
			
			if ($(h).parent().parent().attr('id') == 'menu_header') {
				
				var itm = $(h).parent().children('a').attr('rel');
			
				toggleMenu( itm );
				
			} else {
				toggleMe( $(h).parent().parent().children('.toggle_content') );
			}
			
		}
		
		
		$('.toggle_header').click(function (event) {
			toggleMe( $(event.target).parent().children('.toggle_content') );
		});
		
		
		function toggleMe(t) {
			animatedcollapse.toggle( $(t).attr("id") );
			var clickedItm = $(t).attr("id");
			
			$('.toggle_close').each(function() {						 
				
				var currentItm = $(this).parent().parent().children('.toggle_content').attr("id");
				if (clickedItm != currentItm ) {							 
					$(this).attr('class', 'toggle_open');
				}
			});
			
			
			var toggleBtn = $(t).parent().children().children('.toggle_open, .toggle_close');
			
				if (toggleBtn.attr('class') == 'toggle_open') {
					toggleBtn.attr('class', 'toggle_close');
					
				} else if (toggleBtn.attr('class') == 'toggle_close') {
					toggleBtn.attr('class', 'toggle_open');
					
				}
	
			}
			
		function closeMe(t) {
			animatedcollapse.addDiv( $(t).attr("id") , 'fade=1, hide=1, group=one');
		}
		
		function initMe(t) {
			animatedcollapse.addDiv( $(t).attr("id") , 'fade=1, group=one');
		}
			
	animatedcollapse.init();
	
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	GALLERY CYCLE
	================================================================================ */
	
	//this is the new way
	
	for(i=1; i<30; i++) {
		var str = "#imgset" + i;
		$(str).cycle({ 
			fx:    'fade', 
			speed:	1000,
			timeout:  1000
			}).cycle('pause');
			
			$(str).hover(function() {
								 
				$(this).cycle('resume');
			},function() {
				$(this).cycle('pause');
			});
	}
	
		/*
		
		//this is the old way
		$('#imgset1, #imgset2, #imgset3, #imgset4, , #imgset5 , #imgset6, #imgset7, #imgset8, #imgset9, #imgset10, , #imgset11 , #imgset12').each(function() {
				$(this).cycle({ 
				fx:    'fade', 
				speed:	1000,
				timeout:  1000
				}).cycle('pause');
				
				$(this).hover(function() {
					$(this).cycle('resume');
				},function() {
					$(this).cycle('pause');
					});
		});
		*/

/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	DETAIL PAGES GALLERY CYCLE
	================================================================================ */
	
	if ( $('body').attr('id') == 'detail') {
		
			 $('#detailset').each(function() {
										   
				$(this).cycle({ 
				fx:    'fade', 
				speed:	1000,
				timeout:  4000,
				 prev:   '#prev', 
				 next:   '#next',
				 after:   onAfter,
				 //pager:  '#pager',
				 nowrap:  1,
				pagerAnchorBuilder: function(idx, slide) { 
				 // return selector string for existing anchor 
				return '#nav li:eq(' + idx + ') a'; 
				} 
				}).cycle('pause');
				
				$(this).hover(function() {
					$(this).cycle('resume');
				},function() {
					$(this).cycle('pause');
					});
			});
		}
	
	
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	ANIMATED BACKGROUND IMAGES
	================================================================================ */
	
	$(".toggle_header, #menu_header li").css({backgroundPosition: '0px 0px'}).hover(
		function() {
			var h = 100 - $(this).height();
			$(this).animate({backgroundPosition:'(0px -' + h + 'px)'});
		},
		function() {
			$(this).animate({backgroundPosition:'(0px 0px)'});
		}
	);
	
	/* these items have some padding */
	$("ul#nav a").css({backgroundPosition: '0px 0px'}).hover(
		function() {
			$(this).animate({backgroundPosition:'(0px -70px)'});
		},
		function() {
			$(this).animate({backgroundPosition:'(0px 0px)'});
		}
	);

/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	FEEDBACK FORM VALIDATION
	================================================================================ */
	
	if ( $('body').attr('id') == 'contact') {
		$("#feedbackForm").validate();
		
		
		if (jQuery.url.param("confirm") == 'true') {
			$('#confirmation').show();
		} else {
			$('#confirmation').hide();
		}
	}
	
	
	
/*	////////////////////////////////////////////////////////////////////////////////

    --------------------------------------------------------------------------------
	
	GOOGLE MAPS
	================================================================================ */
	
	var map = null;
    var geocoder = null;

    function initMap() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(39.859123, -86.14593), 13);
		map.removeMapType(G_HYBRID_MAP);
		
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addControl(new GSmallMapControl());
		
        geocoder = new GClientGeocoder();
		showAddress("5771 Central Ave, Indianapolis, IN");
      }
    }
	
	function unloadMap() {
		/*alert('unloadMap');*/
		GUnload();
	}

    function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml("<h6>Pica Studio</h6><ul><li>5771 Central Avenue</li><li>Indianapolis, IN 46220</li><li>317 847 0744</li></ul>");
			  
            }
          }
        );
      }
    }
	
	if ( $('body').attr('id') == 'contact') {
		initMap();
		$(window).unload( unloadMap );
	}
	
});
