//$(function(){
//});

//	this takes care of orientation changes
//	from: http://stackoverflow.com/questions/6448465/jquery-mobile-device-scaling
if (navigator.userAgent.match(/iPhone/i)) {
    $(window).bind('orientationchange', function(event) {
        if (window.orientation == 90 || window.orientation == -90 || window.orientation == 270) {
            $('meta[name="viewport"]').attr('content', 'height=device-width,width=device-height,initial-scale=1.0');
        } else {
            $('meta[name="viewport"]').attr('content', 'height=device-height,width=device-width,initial-scale=1.0');
        }
    }).trigger('orientationchange');
};

//	from http://alastairc.ac/2010/03/detecting-touch-based-browsing/
function isTouchDevice() {
	var el = document.createElement('div');
	el.setAttribute('ongesturestart', 'return;');
	if (typeof el.ongesturestart == "function") {
		return true;
	}
	return false;
}

$(document).ready( function() {

	$('.videobutton').bind('click', function() {
		$(this).toggleClass('activebutton');
		$('.appvideo').toggleClass('appblockhidden');
/*		
		if ($('.appvideo').hasClass('appblockhidden')) {
			$('.appvideo video').get(0).pause();
		} else {
			$('.appvideo video').get(0).play();
		}
*/
		$('.appscreens').addClass('appblockhidden');
		$('.screensbutton').removeClass('activebutton');

	});

	$('.screensbutton').bind('click', function() {
		$(this).toggleClass('activebutton');
		$('.appscreens').toggleClass('appblockhidden');

		$('.appvideo').addClass('appblockhidden');
		$('.videobutton').removeClass('activebutton');

	});
	
	$('.mediabuttons').show();
	$('.appscreens').addClass('appblockhidden');
	$('.appvideo').addClass('appblockhidden');

});

var Appblocks = function AppblocksConstructor() {
	var self = this;

	$(document).ready( function() {
		SetupScreens();
	});

	function SetupScreens() {
		if ($('.appscreens').length == 0) return;
		
		var sswidth = 320;
		if ($('body').hasClass('bipadapp')) sswidth = 388;
		//	if screen size is less than 480px, then half the images
		//	technique from: http://www.jensbits.com/2011/03/04/mobile-detection-with-css-and-jquery-part-2/
		if ($('.devicedetect').css("text-transform") == "capitalize") sswidth /= 2;
		
		sswidth += 24;	//	12px side paddings
		
		//	setup scroll area width
		var scrollerWidth = $('.appscreens li').length * sswidth;
		$('.appscreens ul').width( scrollerWidth );

	}
	
	return self;
}();


