ig.module( 
	'game.main' 
)
.requires(
	'game.sheep-game',
	'game.title',
	'game.scores',
	'game.scores-submit',
	
	// Plugins
	'plugins.simple-splash-loader'
)
.defines(function(){

if( document.location.href.match(/(\?|&)nosound/) ) {
	ig.Sound.enabled = false;
}

// if (ig.ua.mobile) {
// 	ig.Sound.enabled = false;
// }

if (!ig.defaults) {
	ig.defaults = {};
}

var windowWidth = window.innerWidth || 480;
var windowHeight = window.innerHeight || 320;

var gameHeight = 320;
var gameWidth = parseInt(windowWidth / (windowHeight / gameHeight));

ig.main( '#canvas', Title, ig.defaults.frameRate || 30, ig.defaults.width || gameWidth, ig.defaults.height || gameHeight, ig.defaults.scale || 1, ig.SimpleSplashLoader );

var canvas = document.getElementById('canvas');
canvas.style.width = "100%";
canvas.style.height = "100%";

try {
	if (Playtomic)
		Playtomic.Log.View(2174, "29ce7c8c2a524963", document.location);
} catch (e) { }
	
});

var localyticsOpts = {
	appVersion: "v1.0"
};

ig.localyticsSession = LocalyticsSession("5f3d3361ff195cfbba45adf-18396d16-39a0-11e3-3ccf-00a426b17dd8", localyticsOpts);
// ig.localyticsSession = LocalyticsSession("DUMMY", localyticsOpts);
ig.localyticsSession.open();
ig.localyticsSession.upload();
ig.localyticsSession.binarySearch=function(a,fromIndex,toIndex,key){
	var low=fromIndex;
	var high=toIndex-1;
	while(low<=high){
		var mid=(((low+high)/2)|0);
		var midVal=a[mid];
		if(midVal<key){
			low=mid+1;
		}else{
			if(midVal>key){
				high=mid-1;
			}else{
				return mid;
			}
		}
	}
	var t=-(low+1);
	return t;
}
ig.localyticsSession.createRangedAttribute=function(actualValue,steps){
	if(steps.length==0){
		throw "steps length must be greater than 0";
	}
	var bucket="";
	if(actualValue<steps[0]){
		bucket="less than "+steps[0];
	}else{
		if(actualValue>=steps[steps.length-1]){
			bucket=String(steps[steps.length-1])+" and above";
		}else{
			var bucketIndex=ig.localyticsSession.binarySearch(steps,0,steps.length,actualValue);
			if(bucketIndex<0){
				bucketIndex=-bucketIndex-2;
			}
			if(steps[bucketIndex]==steps[bucketIndex+1]-1){
				bucket=String(steps[bucketIndex]);
			}else{
				bucket=String(steps[bucketIndex])+"-"+String(steps[bucketIndex+1]-1);
			}
		}
	}
	return bucket;
}
ig.localyticsSession.createRangedAttribute2=function(actualValue,minValue,maxValue,stepV){
	if(stepV<1){
		return "";
	}
	if(minValue>=maxValue){
		return "";
	}
	var stepQuantity=(((maxValue-minValue+stepV)/stepV)|0);
	var steps=new Array(stepQuantity+1);
	for(var currentStep=0;currentStep<=stepQuantity;currentStep=currentStep+1){
		steps[currentStep]=minValue+currentStep*stepV;
	}
	var t=ig.localyticsSession.createRangedAttribute(actualValue,steps);
	return t;
}

// http://articles.sitepoint.com/article/iphone-development-12-tips/2

// http://twitter.com/home?status=Ваш текст
// http://www.facebook.com/sharer.php?u=Ссылка на станицу

// http://articles.sitepoint.com/article/iphone-development-12-tips/2
/*
if (ig.ua.mobile) {
	var setOrientation = function(e) {
		if (window.orientation == null)
			return;
		
		var orient = Math.abs(window.orientation) === 90 ? 'landscape' : 'portrait';  
		var cl = document.body.className;  
		cl = cl.replace(/portrait|landscape/, orient);  
		document.body.className = cl;
	}
	window.addEventListener('orientationchange', setOrientation, false);
	window.setTimeout(setOrientation, 0);
}
*/