var core = {
	sliderIntervalID: null,
	interval: 0,
	restart: 0,
	bootstrap: function () {
		core.enhanceMenu();
		//if( !$.browser.msie ) { core.menuAction(); }
		//else { if( !$.browser.version == "7.0" ) { core.menuAction(); } }
		//commentate da jeve+davide per consentire i like di facebook
		core.toggleBox();
		$("#body-background").ezBgInit();
	},
	changePage: function (clickPath) {
		$("#body-background").fadeOut(200, "easeInOutCirc");
		$('#loader-overlay').css({
			'background-color': '#000',
			'background-image': 'url(/public/gfx/ico-loader.gif)'
		}).fadeIn(500, function () {
			$('section').remove();
		});
		$('body').stopTime();
		$('body').oneTime(1000, "changePage", function () {
			$.ajax({
				url: clickPath.attr('href') + '?air=1',
				success: function (data) {
					var js = "";
					for (i = 0; i < data.toString().indexOf('<section'); i++) {
						js += data.charAt(i);
					}
					var html = "";
					for (i = data.toString().indexOf('<section'); i <= data.length; i++) {
						html += data.charAt(i);
					}
					$('#body-background').before(innerShiv(html));
					$('#body-background').before(js);
					$('#loader-overlay').fadeOut(500);
				}
			})
		})
	},
	menuAction: function () {
		$('header figure a, nav > ul > li > a').click(function () {
			if ( (!$(this).hasClass('active') && $(this).attr('href') != "javascript:void(0)") || ($(this).hasClass('current-page-ancestor') && $(this).attr('href') != "javascript:void(0)") ) {
				var clickPath = $(this);
				$('header figure a, nav ul li a').removeClass('active');
				$(this).addClass('active');
				core.changePage(clickPath);
			}
			return false
		});
		$('nav ul > li > ul > li > a').click(function () {
			if (!$(this).hasClass('active')) {
				var clickPath = $(this);
				$('header figure a, nav ul li a').removeClass('active').removeClass('current-page-ancestor');
				$(this).addClass('active');
				$(this).parent().parent().parent().find('>a:first-child').addClass('active').addClass('current-page-ancestor');
				core.changePage(clickPath);
			}
			return false
		});
	},
	enhanceMenu: function () {
		$("nav ul").superfish({
			speed: 200,
			delay: 300
		})
	},
	loadBackground: function (pathImg) {
		$("#body-background").fadeOut(200, "easeInOutCirc", function () {
			$(this).find('img').attr('src', pathImg);
		})
	},
	toggleBox: function () {
		$('#showhide-button').live('click', function () {
			if ($('#showhide-layer').css('display') != "none") {
				$('#showhide-layer').fadeOut(300, "easeInOutCirc");
				$(this).addClass('toggleClose');
			}
			else {
				$('#showhide-layer').fadeIn(300, "easeInOutCirc");
				$(this).removeClass('toggleClose');
			}
			return false;
		})
	},
	
	loadVideo: function(fileVideo) {
		$('#videoPlayer').flash({
			// test_swf is the flash document
			swf: '/public/assets/NonverBlaster.swf',
			height: 360,
			width: 640,
			allowFullScreen: true,
			wmode: 'transparent',
			// these arguments will be passed into the flash document
			flashvars: {
				mediaURL: fileVideo,
				teaserURL: "/public/assets/preview.jpg",
				allowSmoothing: "true",
				autoPlay: "true",
				buffer: "6",
				showTimecode: "true",
				loop: "false",
				controlColor: "0xFFFFFF",
				controlBackColor: "0x000000",
				scaleIfFullScreen: "true",
				showScalingButton: "true",
				defaultVolume: "100",
				crop: "false",
				controlsEnabled: "true",
				onClick: "togglePlay"
			},
			attributes: {
				id: "nonverblaster"
			}
		});

		/*var attributes = {};
		attributes.id = "nonverblaster";
		attributes.name = "nonverblaster";
		attributes.bgcolor = "#000000";
		swfobject.embedSWF("/public/assets/NonverBlaster.swf", "videoPlayer", "640", "360", "9", "js/expressinstall.swf", flashvars, params, attributes);*/
	}
};
