$mySideHolder = "<div class='sideIms' id=''></div>";
$myEtsyBadge = "<div id='snail'></div><div id='etsyBadge'><div id='tweetHolder'><div id='twitter'></div></div><a href='http://www.etsy.com/shop/gabiReith'><img src='http://www.etsy.com/images/community/resources/badges/WOLF125.jpg' /></a></div><a href='index.htm#sec_comments'><div id='leaveComment'></div></a>";
$myTwitterFollowButton = "<a href='https://twitter.com/gabiReith' class='twitter-follow-button' data-show-count='false'>Follow Small Stories</a><script src='//platform.twitter.com/widgets.js' type='text/javascript'></script>";
$normalCol = '#5BC8F1';
$xmasCol = '#197800';
$changeBGs = ['#zoomIn','#SMALL_holder','#SMALL_bod','#leaveComment'];

$(document).ready(function(){
    
    /*============= load in some fake includes - menu & comment button ======== */
    
    $.get('menu.htm', function(data) {
          $('#nav').html(data);
         
    });
    
    
	$('body').append($myEtsyBadge);
    
	$('#SMALL_holder').append($myTwitterFollowButton);
    
	
	$('img').css('border', 'none');	
    
	$('.gabiEmail').click(function(){document.location = 'mailto:gabi@g-r-a.co.uk'});
	
		$('.inner').hover(function(){
		   $oW = $(this).width();
		   $oH = $(this).height();
		   $me = $(this);
								   
		$(this).stop(true, false).animate({ width: $oW + 200, height: $oH}, 500, 'swing', function(){snailPosition($me)});
				}, function() {
		$(this).stop(true, false).animate({ width: $(this).parent().width() - 20 }, 100, function(){killSnail()});
	});
	
	if (isiPod()){
			/* ===========  window.location.replace("ipod.htm"); return false; ====== */
	}
    
                
        $(".feedburnerFeedBlock li a").css({'color':'#FFF'});
		
		  /*=============== SHOP ELEMENTS ============= */ 
		$('.ppButton').hide();
		$('.shopTableCell').each(function(index) {
			var myIm = $(this).attr('id');
            var myProduct = $(this).attr('data-product');
				$(this).css({'background-image':'url(images/stock/thumbs/'+ myProduct + '/' + myIm +'.jpg)'});
		});
				
		$('.shopTableCell').hover(
			  function () {
				$('#zoomIn').css({'background-image':'url(images/stock/fullsize/'+ $(this).attr('data-product') + '/' + $(this).attr('id') +'.jpg)'});
				$('#zoomAll').stop(true, false).animate({left: "385px"}, 300);
				$(this).find('.ppButton').show('fast');
			  },
			  function () {
				$('#zoomAll').stop(true, false).animate({left: "10px"}, 200);
				$(this).find('.ppButton').hide('fast');
			  }
		  );
        
        if($('body').attr('id') == 'pg_xmas'){
            $('#small_cloud_tr').css({'background-image':'url(images/xmas_box.png)'});
            $.each($changeBGs, function(i, val) {
                  $(val).css({'background-color':$xmasCol});
               });
        }else{
            $.each($changeBGs, function(i, val) {
                  $(val).css({'background-color':$normalCol});
               });
        }
        
        
    
    
	$.getJSON("http://twitter.com/statuses/user_timeline/gabiReith.json?callback=?", function(data) {
		$("#twitter").html(data[0].text);
	});
    
    
	
	killSnail();
    
		
});

function snailPosition(x){
	$('#snail').css('width','60px');
	$('#snail').css('left',x.offset().left + 330);
	$('#snail').css('top',x.offset().top-34);
	$('#snail').animate({
						 left: '+=200px'
						}, 10000, function() {});
	openImages(x);
}

function openImages(x){
		x.append($mySideHolder);
		if(x.attr("id")){
			$myIm = 'url(images/side/'+x.attr("id")+'/'+(Math.floor(Math.random()*3)+1)+'.jpg)';
		}else{
			$myIm = 'url(images/side/sideHolder.png)';
		}
		$('.sideIms').css({'left':x.position().left + 400, 'top':x.position().top + 30, 'height':(x.height()-10), 'background-image':$myIm});
		$('.sideIms').animate({
		width: '170px'
	  }, 500, function() {
		
	  });
}

function killSnail(){	
	$('.sideIms').remove();
	$('#snail').stop();
	$('#snail').css('width',0);	
	$('#snail').css('background-image','url(images/snails/snail'+(Math.floor(Math.random()*5)+1)+'.png)');
}
			
function isiPod(){
	return (
        (navigator.platform.indexOf("iPhone") != -1) ||
        (navigator.platform.indexOf("iPod") != -1)
    );
}
						   
function showDiv(what, vis){
	myDiv = document.getElementById(what);
	if(vis==1){
			myDiv.style.visibility = 'visible';
	}else{
			myDiv.style.visibility = 'hidden';
	}
	
}
			
	
	
