if(typeof(console) === 'undefined') {
    var console = {}
    console.log = console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
}


/*********
 *
 * These are the quick and dirty hacks for switching between the two column view and the "home page" view.
 * If you need to change something, see if you can first think of something better.
 *
 */

var content;
/********CSS MAGIC *************************************/
 /*
 * We read some attrs from CSS for use with animate() & css() later.
 * Just sticking the relevant class over the object does not work that well,
 * random glitches here and there.
 * Or maybe I can't code.
 * 
 */

$.get('/media/static/ragazzo.css', function(data){
    content= data;
//    console.log(content);
    regex = /.rightpane\s*\{\s*width\s*\:\s*(\d*)\s*/;
    //content.});
    rightpane = content.match(regex)[1];
    window.menu_targetWidth=rightpane;

    regex = /.leftpane\s*\{\s*width\s*\:\s*(\d*)\s*/;
    //content.});
    leftpane = content.match(regex)[1];
    window.cage_targetWidth=leftpane;
    


});
/********CSS MAGIC *************************************/

window.slideArray=new Array();

window.slideArray["generic"] = [
				{ src: '/media/static/img/banner/ex1.jpg' },
				{ src: '/media/static/img/banner/ex2.jpg' }
				];

window.slideArray["azienda"] = [
				{ src: '/media/static/img/banner/azienda1_03.png' },
				{ src: '/media/static/img/banner/azienda2_03.png' }
				];

window.slideArray["prodotti"] = [
				 { src: '/media/static/img/banner/prodotti1_03.png' },
				 { src: '/media/static/img/banner/prodotti2_03.png' }
				 ];

window.slideArray["servizio"] = [
		    { src: '/media/static/img/banner/servizio1_03.png' },
		    { src: '/media/static/img/banner/servizio2_03.png' }		];

window.slideArray["faq"] = [
		    { src: '/media/static/img/banner/faq1_03.png' },
		    { src: '/media/static/img/banner/faq2_03.png' }		];

window.slideArray["news"] = [
		    { src: '/media/static/img/banner/news1_03.png' },
		    { src: '/media/static/img/banner/news2_03.png' }		];


window.slideArray["contatti"] = [
		    { src: '/media/static/img/banner/contatti1_03.png' },
		    { src: '/media/static/img/banner/contatti2_03.png' }		];

/*
 * This is mostly junk, but it kind of works.
 * So, why changing it? Heheh.
*/
	function generic_init() {

			window.cage_is_hidden = true;
		//// $('a.dumb').bind('click',function(event){
		////    
		////    event.preventDefault();
		////	
		////    $("#menu_cart").animate({"top":-7})
		////	href_url =	this.pathname
		////
		////	if (navigator.appName=="Microsoft Internet Explorer")
		////	{
		////	    href_url = "/"+href_url;
		////	}
		////	    // IE is apparently the only browser not to return the traliljng slash, so we add it ourselves.
		////	
		////	$('#header_verynice').animate({'height':468});
		////	$("#content").css({"width":890});
		////	$('#placeholder').crossSlideStop()
		////	$("#typematic_main").fadeIn();
		////	type_o_matic_start()
		////	$("#container").empty();
		////	window.menu_is_hidden = true;
		////	$("#cage").hide();
		////	$("#menu").hide();
		////	
		////	/*
		////	$("#cage").animate({"opacity":0.01}, function () {
		////	    
		////	    // Just like fadeOut(), except that it doesn't hide() the div.
		////	    // Stupid workaround, I know, but couldn't think of anything better.
		////	    
		////				$("#cage").css({"width":0})
		////				$("#content").animate({"height":$("#newsthingy").height()+20});
		////				$("#menu").animate({"width":0}, function(){ $(this).hide()});
		////	
		////			//	$("#newsthingy").animate({"width":1, "opacity":1}, function(){ $("#newsthingy").show().animate({"width":890}) });
		////				
		////	});
		////	*/
		////	$("#newsthingy").show();
		////	
		////	
		////	
		////	window.cage_is_hidden = true;
		////	
		////	window.cage_is_hidden_safari = true;
		////	
		////	$.get(href_url,{"barebones":"true"},function(response){ 
		////	
		////	});
		////	    
		////});
		// 
		//$('a.sensible').bind('click',function(event){
		//    
		//			    // event.preventDefault();
		//			    $("#cage").css({"width":window.cage_targetWidth, "opacity":1});
		//		//	    if ($("#menu").width() > 0) {
		//		//		    window.menu_must_fade=true;
		//		//	    } else {
		//			    $("#menu").css({"width":window.menu_targetWidth, "opacity":1});
		//			//	$("#menu").animate({"width":window.menu_targetWidth, "opacity":1});
		//			//	console.log ("Accordion craze!")
		//		//	    }
		//	    //*/
		//			    $("#cage").fadeIn();
		//			    $('#header_verynice').animate({'height':120});
		//			    $("#placeholder").fadeIn();
		//			    type_o_matic_stop();
		//			    $("#typematic_main").fadeOut();
		//			    $("#newsthingy").css({"width":0});
		//			    $("#newsthingy").hide();
		//			    
		//			    // function(){ $("#newsthingy").hide()})
		//			    
		//			    $("#placeholder").fadeOut(
		//				function() {
		//				    $(this).fadeIn().crossSlide({
		//				    sleep: 4,
		//				    fade: 2
		//				}, window.slideArray["generic"]);
		//			    });
		//			    
		//			    
		//			    href_url =	this.pathname
		//				    
		//			    if (navigator.appName=="Microsoft Internet Explorer") href_url = "/"+href_url;
		//			    
		//			  //  $("#newsthingy").fadeOut();
		//			    $("#magicscroll").fadeIn().load(this.pathname+"?barebones=true");
		//			    $("#menu").fadeIn().load(this.pathname+"?menu=true");
		//			    
		//			    
		//			    /*
		//			    setTimeout(function() {
		//				$("#cage").height(400);
		//				$("#content").height(400);
		//			    }, 200);*/
		//
		//} );
		//
		
		$('a.smart').bind('click',function(event){
		 $(".flying_menu_bar").fadeOut(); 
		 if (window.disableFunnyAnimation) return true; 
		    $("#menu_cart").animate({"top":0})
		    event.preventDefault();
		    
		    if(window.cage_is_hidden_safari) {
			$("#cage").css("opacity", 0.01)
			window.cage_is_hidden_safari=false;
		    }
		    
		    // Workaround preventing webkit to act stupid

		    window.currentSection = $(this).attr("href").replace(/\//g, "")
		    
		    $("a.smart").unbind('mouseenter').unbind('mouseleave')
		    
		    thething=$(this).children().filter("div [id$='_glow']");
		    
		    $("div[id$='_glow']").not(thething).css({"opacity":0});
		    $(thething).css({"opacity":1});
		    $("a.smart").unbind('mouseenter').unbind('mouseleave')
		    $("a.smart").children().unbind('mouseenter').unbind('mouseleave')
		    $("a.smart").not($(thething).parent()).hover(
			function() {
			    $(this).children().filter("div[id$='_glow']").stop().animate({"opacity": "1"}, "fast");
			},
			function() {
			    $(this).children().filter("div[id$='_glow']").stop().animate({"opacity": "0"}, "fast");
			}
		    );
		    $("#cage").animate({"width":window.cage_targetWidth});
		    $("#content").animate({"width":window.cage_targetWidth});

		    if ($("#menu").width() > 0) {
			window.menu_must_fade=true;
		    } else {
			$("#menu").animate({"width":window.menu_targetWidth});
		    }
			
		    $("#menu").animate({"width":window.menu_targetWidth});
		    // console.log("We've Got A Groovy Thing Goin'")
		    $('#header_verynice').animate({'height':120});
		    $("#placeholder").fadeIn();
		    type_o_matic_stop();
		    $("#typematic_main").fadeOut();
		    
		    $("#newsthingy").animate({"width":0}, function(){ $("#newsthingy").hide()})
		    $("#placeholder").fadeOut(
						function() {
						    $(this).fadeIn().crossSlide({
						    sleep: 4,
						    fade: 2
						}, slideArray[window.currentSection]);
					    });
		    href_url =	this.pathname
			
		    if (navigator.appName=="Microsoft Internet Explorer")
		    {
									//			 alert("IE IS DOG SHIT");
			href_url = "/"+href_url;
		    }

		    // "_trackEvent" is the pageview event, 
		    _gaq.push(['_trackPageview', href_url]);
		    
		    if(window.cage_is_hidden) {
			$("#cage").height($("#newsthingy").height())
			loadMenu(href_url);
    		window.cage_is_hidden=false;
		    } else {
			loadMenu(href_url)
		    }
		});
	    }
	    

