//JQuery - Javascript 

$().ready(function() {
	    /*$.preloadCssImages();*/
		$(document).pngFix(); 
		
		$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
		//$('#s1').addClass('web');
		//$('div#portfolio').click();
		loadFolio(1,'web',0,1);
		
		var h = screen.availHeight;
		var w = screen.availWidth;
		

		if(h <= 750)	 {
			$('ul#topNav').show();
			$('div#portfolio, a#folio-menu').click(function() {
			$.scrollTo({top:200, left:0 },'slow');					  
											  });
			$('div#aboutMe, a#about-menu').click(function() {
														  
			$.scrollTo({top:500, left:0 },'slow');					  
											  });
	}
	

	
		/*$('#accordion').accordion({
					header: "div.foliohead",
					collapsible: false,
					autoHeight:false,
					active: true,
					//clearStyle:true,
					change: function () {
				//something here
				alert('changed!');
					
					}
					});*/

				
										 
$('a.mailto').click(function() {
				var a = $(this);
				var href = $(this).attr('href');
				var title = $(this).attr('title');
				$(this).attr('href', 'mail' + 'to:' + title +"@"+href);	
							});
		
		
	/*$('a#folio-menu, a#folio-img').click(function(){
				$('div#portfolio').click();								  
	});
	
	$('a#about-menu').click(function() {
		$('div#aboutMe').click();							 
	 });
	
	$('a#contact-menu').click(function() {
		$('#accordion').accordion('option', 'active', 1);
		$('a#contact').click();
		toggleShadow('div#aboutMe');
									   });

	$('div#aboutMe').click(function() {
		reArrange ();
		toggleShadow(this);
		$('#s2').load('about.htm', function() {
		
		$('a.active').removeClass('active');
		$('a#about').addClass('active');
		//
										});

			});*/
	
	$('div#portfolio').click(function() {
			//$('#accordion').accordion('option', 'clearStyle', true);						  
			//loadFolio(1,'web',0,1);
			//$('a.web').click();
			
			//toggleShadow(this);
									  });
	
	
	
	/*$('div#blog').click(function() {
		 toggleShadow(this);
		 
	//$('#loader').show();
		$('iframe').src('blog/index.php', function(duration) { 
 // alert("That took " + duration + " millis.");
// $('#loader').hide();
 
});*/

		/*$('#blogframe').load('blog/index.php');
			reArrange();
			 });*/
		
	
	/*
		$('a#about').click(function() {
			loadContent(this,'#s2');
			});*/
		
	 
	
/*	$('a#contact').click(function() {
		
			$('#s2').load('contact.htm', function() {
				var a = 'a.mhmail';
				var href = 'mary@maryahayne.com';
	
				obEmail(a, href);
														
		 	   });*/
			
		$(this).parent('li').siblings().children('a.active').removeClass('active');
		$(this).addClass('active');
		
		 // });
	

	$('a#resume').click(function() {
			loadContent(this,'#s2');
			});

//FUNCTIONS

		function obEmail (a, href, title) {
			$(a).click(function() {
			$(this).attr('href', 'mail' + 'to:' + title +"@"+href);
								 });
		}
		 
		function loadContent(sel,el) {
		
			var type = $(sel).attr('id');
	
			$(el).load(type + '.htm', function () {
											});
			$(sel).parent('li').siblings().children('a.active').removeClass('active');
			$(sel).addClass('active');
			

	}
	
	   function loadFolio(i, type, subtype, idx)  {
		
		
		var el = '#s' + i;
		
		$(el).attr('class', type);


			function onBefore () { 
				$('a.active').removeClass('active');
				$('a.' + type).addClass("active");
				
				var a = $(this).width();
				
				if(a<1028) {
				$('.foliocontent').width(a+78);
				}
				
				$(el).width(a);
				
		
				
				switch(type) {
					
					case 'web':
					
					$('#contentBg').css({height: '430px'});
					$('#s1').css({height: '430px'});
					$(this).find('.txtholder').css('bottom', '10px');
					break;
					
					case 'graphic':
					
					var h = $(this).find('img.graphic').height();
					var p = $(this).height();
					var m = (p - h) * .20;
				
					$(this).find('.panel-wrapper').css('marginTop',m);
					$(this).find('div.vert').css('marginTop', 0);
					$(this).find('img.vert').css('marginTop', 5);
					
					$('#contentBg').css({height: '421px'});
					$('#s1').css({height: '420px'});
					break;
					
					case 'logo':
					
					$('#contentBg').css({height: '420px'});
					$('#s1').css({height: '420px'});
					break;
					
					case 'icon':
					$('#contentBg').css({height: '420px'});
					$('#s1').css({height: '420px'});
					
					var h = $(this).find('ul.horz').height();
					var p = $(this).height();
					var t = 10  + ((p - h) * .05);
					
					
					$(this).find('ul.horz').css('marginTop',t);
					break;
					
				}
				
				
				
				
				
				}
			function onAfter () {
			/*$("img.reflect").reflect();*/
			
			if(type == 'icon') {	
			/*reSizeDiv();*/
			
		var i = $(this).find('ul.horz li img').width();
		var w = (3*i) +104+'px';
		
		$('div.icon ul.horz').css('width',w);
		
			}
						
			}
			
  $(el).load('_getData3.php','type='+type+'&subtype='+subtype, function() {
				$(el).cycle({
					 fx:     'scrollHorz',
					 prev:   '#prev' + i, 
    				 next:   '#next' + i,
    				 timeout: 0,
					 cleartype:true,
					 cleartypeNoBg: true,
					 before: onBefore,
					 after: onAfter
					 
					 
					 
				});						
			$(el).addClass('insetShadow')		
																		
			}); 
  
      $(document).bind('keypress', function(e) {
        if (e.keyCode == 37)
            $(el).cycle('prev');
         else if (e.keyCode == 39)
            $(el).cycle('next');
    });
		 
	 }  				
	
	
/*function toggleShadow(el) {
	var el = $(el);
	if((el).hasClass('longshadow')) {
		removeShadow();
		
	}else{
		addShadow(el);
	}
}

function addShadow(el) {
					$('*').removeClass('longshadow');
					//$(el).css('border-top','none');
					$(el).addClass('longshadow');
					//$(this).parent().find('div.foliohead').css('margin-top','8px');
					//$(el).next().find('div.subNav').css('margin-top','15px');
										   }
										   
 function removeShadow () {
					$('*').removeClass('longshadow');
					//$('div.foliohead').css('border-top','1px solid #e1e1e1');
					$('div.subNav').css('margin-top', 0);
										  }
*/

//END FUNCTIONS


 
 /* $('div.subNav').eq(0).find('ul').eq(1).children('li').click(function() {

	var a = $(this).parent().index() +1;
	var b = $(this).find('ul').attr('id');
	var c = $(this).find('a').attr('class');
	var d = $(this).index() +1;
	

	loadFolio(a, b,c, d);
	
	});*/
 
  $('div.subNav').eq(0).find('ul').eq(0).children('li').click(function() {
    $(this).find('a').removeClass('active');
	var a = $(this).parent().index() +1;
	var b = $(this).find('a').attr('class');
	var c = $(this).index() +1;
	
	//$('#s1').removeClass().addClass(b);
	
	loadFolio(a, b,0, c);
	
	
	
	});
	
loadFolio(1,'web',0,1);
			
	
			   
		
   $('ul li:last-child').css('border','none');
   
});
