function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

function htmlspecialchars_decode (string, quote_style) {
   
    var optTemp = 0,
        i = 0,
        noquotes = false;
    if (typeof quote_style === 'undefined') {
        quote_style = 2;
    }
    string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
    var OPTS = {
        'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE': 1,
        'ENT_HTML_QUOTE_DOUBLE': 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE': 4
    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
        quote_style = [].concat(quote_style);
        for (i = 0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            } else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }
        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
        // string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
    }
    if (!noquotes) {
        string = string.replace(/&quot;/g, '"');
    }
    // Put this in last place to avoid escape being double-decoded
    string = string.replace(/&amp;/g, '&');
 
    return string;
}
//jQuery(document).ready(function() {

jQuery(window).load(function() {
	var open = false;
	jQuery('#footerSlideContainer').css('z-index','1000');
	jQuery('#footerSlideButton').hover(function() {
if(open === false) {
			jQuery(this).css('backgroundPosition', 'bottom left');
		} else {
			jQuery(this).css('backgroundPosition', 'top left');
		}}, function() {
if(open === false) {
			jQuery(this).css('backgroundPosition', 'top left');
		} else {
			jQuery(this).css('backgroundPosition', 'bottom left');
		}});
	
	jQuery('#prev').hover(function() {
			jQuery(this).css('backgroundPosition', 'top left');
		}, function() {
			jQuery(this).css('backgroundPosition', 'top right');
});
		jQuery('#next').hover(function() {
			jQuery(this).css('backgroundPosition', 'top right');
		}, function() {
			jQuery(this).css('backgroundPosition', 'top left');
});

	jQuery('#footerSlideButton').click(function() {
		if(open === false) {
		if (mobile=='mstrue') {
			jQuery('#footerSlideContent').animate({ height: '220px' });
			} else {
			jQuery('#footerSlideContent').animate({ height: '220px' });
			}
			jQuery(this).css({'backgroundPosition':'bottom left','-webkit-transform': 'rotate(0deg)','-moz-transform': 'rotate(0deg)','filter': 'progid:DXImageTransform.Microsoft.BasicImage(rotation=0)'});
			open = true;
		} else {
			jQuery('#footerSlideContent').animate({ height: '0px' });
			jQuery(this).css({'backgroundPosition':'top left','-webkit-transform': 'rotate(180deg)','-moz-transform': 'rotate(180deg)','filter': 'progid:DXImageTransform.Microsoft.BasicImage(rotation=2)'});
			open = false;
		}});


 
var vwh = (jQuery(window).height());
   var winh = ('w=' + vwh);

if (mobile!=='mstrue') {
jQuery('.entry-content').height(vwh);
}
function onAfter() {

jQuery('a').each(function(){var a=jQuery(this);var href=a.attr('href');if(href==undefined)
return;var url=href.replace('http://','').replace('https://','');var hrefArray=href.split('.').reverse();var extension=hrefArray[0].toLowerCase();var hrefArray=href.split('/').reverse();var domain=hrefArray[2];var downloadTracked=false;if(jQuery.inArray(extension,analyticsFileTypes)!=-1){downloadTracked=true;a.click(function(){if(analyticsEventTracking=='enabled'){_gaq.push(['_trackEvent','Downloads',extension.toUpperCase(),href]);}else
_gaq.push(['_trackPageview',analyticsDownloadsPrefix+url]);});}
if((href.match(/^http/))&&(!href.match(document.domain))&&(downloadTracked==false)){a.click(function(){if(analyticsEventTracking=='enabled'){_gaq.push(['_trackEvent','Outbound Traffic',href.match(/:\/\/(.[^/]+)/)[1],href]);}else
_gaq.push(['_trackPageview',analyticsOutboundPrefix+url]);});}});




if (mobile!=='mstrue') {
 //set the originals
    var originalWinWidth = jQuery(window).width();
     

    //set the original font size
    var originalFontSizeDESC = Math.round(originalWinWidth/91);
    var originalFontSizeTAGT = Math.round(originalWinWidth/85);
    var originalFontSizeMAIN = Math.round(originalWinWidth/85);
    var originalFontSizePROJ = Math.round(originalWinWidth/71);


    //set the ratio of change for each size change
    var ratioOfChange = 80;
 
    //set the font size using jquery
    jQuery("p.desc").css("font-size", originalFontSizeDESC);
    jQuery("p.desc").css('line-height', Math.round((originalFontSizeDESC * 1.35))+'px');
    jQuery("p.desc").css('margin-top', Math.round((originalFontSizeDESC * 1.35))+'px');    
    jQuery("p.main").css("font-size", originalFontSizeMAIN);
    jQuery("p.main").css('margin-bottom', Math.round((originalFontSizeMAIN))+'px');
    jQuery("span.tagt").css("font-size", originalFontSizeTAGT);
   jQuery("span.tagt").css('margin-bottom', Math.round((originalFontSizeTAGT * .25))+'px');
   jQuery(".project").css("font-size", originalFontSizePROJ);
   jQuery(".project").css('margin-bottom', Math.round((originalFontSizePROJ))+'px');
   jQuery(".first").css("display", "block");

 
jQuery(window).resize(function()
    {
    var vwh = (jQuery(window).height());


        //get the width and height as the window resizes
        var winWidth = jQuery(window).width();
 
 jQuery(".topstuff").css("width", Math.round(winWidth*.90));
 jQuery(".topstuff").css({"margin-top":"4.5%","height":Math.round(vwh*.9),"margin-left":"2%"});
jQuery("#slideshow").css("height", vwh);

 
        //get the difference in width
        var widthDiff = winWidth - originalWinWidth;
 
        //check if the window is larger or smaller than the original
        if(widthDiff > 0)
        {
            //our window is larger than the original so increase font size
            var pixelsToIncrease = Math.round(widthDiff / ratioOfChange);
 
            //calculate the new font size
            var newFontSizeDESC = originalFontSizeDESC + pixelsToIncrease;
            var newFontSizeMAIN = originalFontSizeMAIN + pixelsToIncrease;
            var newFontSizeTAGT = originalFontSizeTAGT + pixelsToIncrease;
			var newFontSizePROJ = originalFontSizePROJ + pixelsToIncrease;

 
            //set new font size
            jQuery("p.desc").css("font-size", newFontSizeDESC);
            jQuery("p.desc").css('line-height', Math.round((newFontSizeDESC * 1.35))+'px');
  			jQuery("p.desc").css('margin-top', Math.round((newFontSizeDESC * 1.35))+'px');    
            jQuery("p.main").css('margin-bottom', Math.round((newFontSizeMAIN))+'px');
            jQuery("p.main").css('line-height', Math.round((newFontSizeMAIN) * 1.35)+'px');
            jQuery("span.tagt").css('margin-bottom', Math.round((newFontSizeTAGT * .25))+'px');
            jQuery("span.tagt").css('line-height', Math.round((newFontSizeTAGT * 1.35))+'px');            
            jQuery("p.main").css("font-size", newFontSizeMAIN);
            jQuery("span.tagt").css("font-size", newFontSizeTAGT); 
            jQuery(".project").css("font-size", newFontSizePROJ);
            jQuery(".project").css('margin-bottom', Math.round((newFontSizePROJ))+'px');            


            }
        else
        {
            //our window is smaller than the original so decrease font size
            var pixelsToDecrease = Math.round(Math.abs(widthDiff) / ratioOfChange);
 
            //calculate the new font size
            var newFontSizeDESC = originalFontSizeDESC - pixelsToDecrease;
            var newFontSizeMAIN = originalFontSizeMAIN - pixelsToDecrease;
            var newFontSizeTAGT = originalFontSizeTAGT - pixelsToDecrease;
    		var newFontSizePROJ = originalFontSizePROJ - pixelsToDecrease;

 
            //set the new font size
            jQuery("p.desc").css("font-size", newFontSizeDESC);
            jQuery("p.desc").css('line-height', Math.round((newFontSizeDESC * 1.35))+'px');
  			jQuery("p.desc").css('margin-top', Math.round((newFontSizeDESC * 1.35))+'px');    
            jQuery("p.main").css('margin-bottom', Math.round((newFontSizeMAIN))+'px');
            jQuery("p.main").css('line-height', Math.round((newFontSizeMAIN) * 1.35)+'px');
            jQuery("span.tagt").css('margin-bottom', Math.round((newFontSizeTAGT * .25))+'px');
            jQuery("span.tagt").css('line-height', Math.round((newFontSizeTAGT * 1.35))+'px');            
            jQuery("p.main").css("font-size", newFontSizeMAIN);
            jQuery("span.tagt").css("font-size", newFontSizeTAGT); 
            jQuery(".project").css("font-size", newFontSizePROJ);
            jQuery(".project").css('margin-bottom', Math.round((newFontSizePROJ))+'px');              
        }
    });

}
}

 // retrieve list of slides from server
 //jQuery.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8"});
    jQuery.getJSON('/slidelist.php', { 'w' : (jQuery(window).height()-61)}, startSlideshow);
        function startSlideshow(slides) {
        
        var totalSlideCount = 1 + slides.length;
        
        var $slideshow = jQuery('#slideshow');
        
        // markup contains only a single slide; before starting the slideshow we 
        // append one slide and prepend one slide (to account for prev/next behavior)
        $slideshow.prepend('<'+htmlspecialchars_decode(slides.pop())+'>');
        $slideshow.append('<'+htmlspecialchars_decode(slides.shift())+'>');

        // start slideshow
        jQuery('#slideshow').cycle({
            fx: 'scrollHorz',
            startingSlide: 1,  // start on the slide that was in the markup
            timeout:  0,
            speed:    500,
            prev:    '#prev',
            next:    '#next',
            before:   onBefore,
            after:	  onAfter
        });
        
   
        
        jQuery(document).bind('keyup', function(e) {
    if (e.keyCode == 37){
        jQuery('#slideshow').cycle('prev');
        jQuery('#prev').css('backgroundPosition', 'top left');
        setTimeout( function(){
      jQuery('#prev').css('backgroundPosition', 'top right');
    },500);

   }  else  if (e.keyCode == 39) {
       //jQuery('.loc').css('visibility','hidden');
       jQuery('#slideshow').cycle('next');
       jQuery(next).css('backgroundPosition', 'top right');
        setTimeout( function(){
      jQuery(next).css('backgroundPosition', 'top left');
    },500);
    
     }  else  if (e.keyCode == 38) {
       //jQuery('.loc').css('visibility','hidden');
       jQuery('#footerSlideContent').animate({ height: '220px' });
			jQuery('#footerSlideButton').css({'backgroundPosition':'bottom left','-webkit-transform': 'rotate(0deg)','-moz-transform': 'rotate(0deg)','filter': 'progid:DXImageTransform.Microsoft.BasicImage(rotation=0)'});
			open = true;
} else  if (e.keyCode == 40) {
       jQuery('#footerSlideContent').animate({ height: '0px' });
			jQuery('#footerSlideButton').css({'backgroundPosition':'top left','-webkit-transform': 'rotate(180deg)','-moz-transform': 'rotate(180deg)','filter': 'progid:DXImageTransform.Microsoft.BasicImage(rotation=2)'});
			open = false;
}
});


        function onBefore(curr, next, opts, fwd) {
   	
            if (!opts.addSlide)
                return;
                
            // have we added all our slides?
            if (opts.slideCount == totalSlideCount)
                return;

            // shift or pop from our slide array 
            var nextSlideSrc = fwd ? slides.shift() : slides.pop();
            
            // add our next slide
            opts.addSlide('<'+htmlspecialchars_decode(nextSlideSrc)+'>', fwd == false);
        };
    };
});

