/* Commercial Artisan site */


/* setup swfObject for header logo */

var flashvars = {};
var params = {};
	params.wmode = "opaque";
var attributes = {};
	attributes.id = "logoswf";
swfobject.embedSWF("/swf/banner3.swf", "logo", "540", "38", "9.0.0", "expressInstall.swf", flashvars, params, attributes);

/* function called by jquery cycle pager */
function onAfter(curr, next, opts) {
    var index = opts.currSlide;
		if (index == 0 ) {
			$('#prev').css("color","#eee");
		} else {
			$('#prev').css("color","#999");
		}
			if (index == opts.slideCount - 1) {
				$('#next').css("color","#eee");
			} else {
				$('#next').css("color","#999");
			}
				$('#pageNum').html( '<span style="color:#F00;"> ' + (opts.currSlide +1) + '</span> / ' + opts.slideCount );
}

$(document).ready(function() {		
						   					   
	/* page background color transitions based on window size */					   
	function resizeIt() {
		if ( $(window).width() > 1000) {
			
			//$('body').css('background','#CCC');
			$('.bg').stop();
			$('.bg').animate( { backgroundColor: '#EDEDED' }, 1000);
		} else {
			$('.bg').stop();
			$('.bg').animate( { backgroundColor: '#FFF' }, 1000);
		}
	}
	
	$(window).resize(function() {		  
				resizeIt();
		});
						   
		
		
		/* jquery cycle configuration */
		$('#featuredwork #gallery, #archivework #gallery').each(function() {
			$(this).cycle({ 
			fx:    'fade', 
			speed:	1000,
			timeout:  0,
			 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');
				});
		});
		
		
												  
		
		
		/* jquery cycle configuration for homepage */
		$('#home #gallery').each(function() {
			$(this).cycle({ 
			fx:    'fade', 
			speed:    3000, 
    		timeout:  7000
			});
		});
		
		
		/* animated collapse div config */
		$('#site-sidebar h3').each(function() {		  
				closeH3( $(this).parent().children('ul') );
		});
		
		$('#site-sidebar h4').each(function() {		  
				closeH4( $(this).parent().children('ul') );
		});
		
		
		$('#site-sidebar h3 a, #site-sidebar h4 a').click(function (event) {
			event.preventDefault();
			toggleMe( $(event.target).parent().parent().children('ul') );
		});
		
		
		function toggleMe(t) {
			animatedcollapse.toggle( $(t).attr("id") );
			}
			
		function closeH3(t) {
			//animatedcollapse.addDiv( $(t).attr("id") , 'fade=1, hide=1, group=pets');
			
			
			var pg = $('body').attr('id');
			var itm = $(t).attr('id');
			
			if (pg == 'featuredwork') {
				
				if (itm == 'fwork') {
					animatedcollapse.addDiv( $(t).attr("id") , 'fade=1, group=one' );
				} else {
					animatedcollapse.addDiv( $(t).attr("id") , 'fade=1, hide=1, group=one' );
				}
				
			} else if (pg == 'archive_alpha' || pg == 'archive_cat' || pg == 'archivework') {
				
				if (itm == 'arch') {
					animatedcollapse.addDiv( $(t).attr("id") , 'fade=1, group=one' );
				} else {
					animatedcollapse.addDiv( $(t).attr("id") , 'fade=1, hide=1, group=one' );
				}
				
			} else if (pg == 'home' || pg == 'contact' || pg == 'about') {
				
				if (itm == 'fwork') {
					animatedcollapse.addDiv( $(t).attr("id") , 'fade=1, group=one' );
				} else {
					animatedcollapse.addDiv( $(t).attr("id") , 'fade=1, hide=1, group=one' );
				}
				
			}
			
		}
		
		
	
		function closeH4(t) {
			var pg = $('body').attr('id');
			var itm = $(t).attr('id');
			
			if (itm == 'byformat') {
				
				if (pg == 'archive_cat') {
					animatedcollapse.addDiv( itm , 'fade=1, group=two' );
				} else {
					animatedcollapse.addDiv( itm , 'fade=1, hide=1, group=two' );
				}
				
				
				
			} else {
				
				if (pg == 'archive_cat') {
					animatedcollapse.addDiv( itm , 'fade=1, hide=1, group=two' );
					
				} else {
					animatedcollapse.addDiv( itm , 'fade=1, group=two' );
				}
				
			}
		}
		animatedcollapse.init();
		
		/* picture / words toggle */
		$('#words').hide();
		
		$('#pictsbtn').click(function (event) {
			//$('#words').hide();
			//$('#pictures').show();
			
			event.preventDefault();
			
			$('#words').fadeOut('slow');
			$('#pictures').fadeIn('slow');
			//setContainerHeight();
			//setContainerHeight();
		});
		$('#wordsbtn').click(function (event) {
			//$('#words').show();
			//$('#pictures').hide();
			
			event.preventDefault();
			
			$('#words').fadeIn('slow');
			$('#pictures').fadeOut('slow');
			//setContainerHeight();
			//setContainerHeight();
		});
		
	resizeIt();
	resizeIt();
	/* call method twice, safari does not seem to react to first call */
});
