
/*
 * smartresize: debounced resize event for jQuery
 *
 * latest version and complete README available on Github:
 * https://github.com/louisremi/jquery.smartresize.js
 *
 * Copyright 2011 @louis_remi
 * Licensed under the MIT license.
 *
 * This saved you an hour of work? 
 * Send me music http://www.amazon.co.uk/wishlist/HNTU0468LQON
 */
(function($) {

var event = $.event,
	resizeTimeout;

event.special[ "smartresize" ] = {
	setup: function() {
		$( this ).bind( "resize", event.special.smartresize.handler );
	},
	teardown: function() {
		$( this ).unbind( "resize", event.special.smartresize.handler );
	},
	handler: function( event, execAsap ) {
		// Save the context
		var context = this,
			args = arguments;

		// set correct event type
        event.type = "smartresize";

		if(resizeTimeout)
			clearTimeout(resizeTimeout);
		resizeTimeout = setTimeout(function() {
			jQuery.event.handle.apply( context, args );
		}, execAsap === "execAsap"? 0 : 100);
	}
}

$.fn.smartresize = function( fn ) {
	return fn ? this.bind( "smartresize", fn ) : this.trigger( "smartresize", ["execAsap"] );
};

})(jQuery);

// =======================================================================
// =======================================================================
// =======================================================================

var kSideMargin = 30;
var kMargin = 5;
var kColumnWidth = 125;
var kGridSize = kMargin + kColumnWidth;

$(function () {
    $(window).bind('smartresize.container', function() {
        var c = $('#container');
        var width = kGridSize *
            Math.floor(($(window).width() - kMargin - kSideMargin) / kGridSize) -
            (kMargin * 3);
        c.css({
            width: width
        });
    }).smartresize();
});


// viewport

var d = window.document;
var orientation = window.orientation;
var viewport = $('meta[name="viewport"]');
var nua = navigator.userAgent;

//d.write('<meta name="viewport" content="width=1024, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />');

if(navigator.userAgent.indexOf('iPhone') > -1){
	d.write('<meta name="viewport" content="width=device-width; initial-scale=0.33;" /><style type="text/css">#members .num { top: -20px; font-size: 125px !important; }</style>');
}else if(navigator.userAgent.indexOf('iPad') > -1){
	//orientation = window.orientation;
	//if(orientation == 90 || orientation == -90){
	//	d.write('<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1" /><style type="text/css">#members .num { top: -20px; font-size: 125px !important; }</style>');	
	//}else{
	//	d.write('<meta name="viewport" content="width=device-width*initial-scale, initial-scale=0.8" /><style type="text/css">#members .num { top: -20px; font-size: 125px !important; }</style>');
	//}
	d.write('<meta name="viewport" content="width=device-width, initial-scale=0.8" /><style type="text/css">#members .num { top: -20px; font-size: 125px !important; }</style>');
	
	//document.getElementById('viewport').content = 'width=' + Math.round(screen.width * window.devicePixelRatio) + ',user-scalable=no';
}

/*
window.onorientationchange = function() {
	orientation = window.orientation;
	viewport = $('meta[name="viewport"]');

	if(nua.indexOf('iPhone') > -1){
		//d.write('<meta name="viewport" content="width=device-width; initial-scale=0.33;" /><style type="text/css">#members .num { top: -20px; font-size: 125px !important; }</style>');
	}else if(nua.indexOf('iPad') > -1){
		if(orientation == 90 || orientation == -90){
			//alert('yoko');
			
			viewport.setAttribute('content', 'user-scalable=no, width=device-width, initial-scale=1');


		}else{
			//alert('tate');
			viewport.setAttribute('content', 'user-scalable=no, width=device-width, initial-scale=0.7');
			//alert(viewport.getAttribute('content'););
		}
		
		alert(viewport.getAttribute('content'));
	}
}*/


