/**
 * Legacy codes
 */
function popup(nom_de_la_page, nom_interne_de_la_fenetre)
{
	w=window.open(nom_de_la_page, nom_interne_de_la_fenetre, 'height=185, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
	return false;
}
/* Modified to support Opera */
function addFav( url, title ){
	if(document.all) {
		window.external.AddFavorite(url, title);
	}
	else if ( window.sidebar ) {
		window.sidebar.addPanel(title, url, "");
	}
	else if ( window.opera && window.print ) {
		var e = document.createElement('a');
		e.setAttribute('href',url);
		e.setAttribute('title',title);
		e.setAttribute('rel','sidebar');
		e.click();
	}
}

/**
 * Combining fadeIn and slideOut effects
 */
jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
}; 

/**
 * Simple animation system
 */
var animConfig 	= {
	'calc': 	{m:'bg',t:'.calcAnim',sp:100,p:2000,s:1,max:9,ox:29,oy:40,i:'images/calc/ca_#.gif'},
	'tooltip': 	{m:'bg',t:'.animInfoBulle',p:4000,sp:100,s:1,max:7,ox:35,oy:1,i:'images/bulle/#.gif'},
	'jeux': 	{m:'anim',t:'.jeux_concours',p:4000,sp:100,s:1,max:2,anim:{pA:{opacity: 0.4},sA:300,pB:{opacity: 1},sB:300}}
}
function execAnim( name ) {
	if ( name == 'all' ) {
		$.each( animConfig, function( k, v ) {
			execAnim( k );
		} );
	}
	else {
		if ( animConfig[name] ) {
			var cfg 	= animConfig[name];
			var speed 	= cfg.sp;
			if($) {
				if ( cfg.s == 1 ) {
					speed = cfg.p;
				}
				if ( cfg.m == 'bg' ) {
					$(cfg.t).css("background", "url("+cfg.i.replace('#',cfg.s)+") no-repeat "+cfg.ox+"px "+cfg.oy+"px");
				}
				else if ( cfg.m == 'anim' ) {
					var animP	= cfg.anim.pA;
					var animSP	= cfg.anim.sA;
					if ( cfg.s == 1 ) {
						animP	= cfg.anim.pB;
						animSP	= cfg.anim.sB;
					}
					$(cfg.t).animate(animP, animSP );
				}
				if ( ++cfg.s > cfg.max ) {
					cfg.s = 1;
				}
				setTimeout( 'execAnim("'+name+'")', speed );
			}
		}
	}
}

/**
 * Creating simple application module
 */
Tine.ns("Tine.impl");
(function() {
	$m = Tine.require("Tine.app.modules", "[SampleModule] require [modules] package");
	$e = Tine.impl;
	
	$e.ProjetMutuelle = function( config ) {
		Tine.merge( this, config );
		$e.ProjetMutuelle.superclass.constructor.call( this, arguments );
	}
	
	Tine.extend( $e.ProjetMutuelle, $m.Module, { 
		initialize: function() {
			// do something
		},
		startModule: function() {
			if ( $ && jQuery ) {
				$('#mainBlock').corner("top 5px cc:#565656");
				$('#leftBlock').corner("top 5px cc:#565656");
				$('#footerBlock').corner("bottom 5px cc:#565656");
				$('#animationCenter').hide();
				$('.jeux_concours').hide();
				$('.devisGratuit').hide();
				$('#animationCenter').slideFadeToggle( 'normal', 'linear',  function() { 
					$('.jeux_concours').fadeIn( 'slow' );
					$('.devisGratuit').fadeIn( 'slow' );
					execAnim( 'all' );
				});
				
				$('#mainBlock').fadeIn( 'slow' );
				$('#leftBlock').fadeIn( 'slow' );
				$('#footerBlock').fadeIn( 'slow' );
				$('.pics').css( "float", "right" );
				$('.pics').css( "width", "65px" );
				$('.pics').css( "height", "65px" );
				$('.pics').cycle({ 
					fx: 'shuffle',
					 shuffle: { top: 8, left: 10 }
				});
			}
		}
	} )
})();

// on document ready
$(document).ready(function() {
	$c = Tine.app;
	$r = Tine.app.resources;
	$e = Tine.impl;
	$('#animationCenter').hide();
	var  app = new $c.ApplicationModel( {
		resources: 		[
			{ id: 'calc1', 		src: 'images/calc/ca_1.gif' },
			{ id: 'calc2', 		src: 'images/calc/ca_2.gif' },
			{ id: 'calc3', 		src: 'images/calc/ca_3.gif' },
			{ id: 'calc4', 		src: 'images/calc/ca_4.gif' },
			{ id: 'calc5', 		src: 'images/calc/ca_5.gif' },
			{ id: 'calc6', 		src: 'images/calc/ca_6.gif' },
			{ id: 'calc7', 		src: 'images/calc/ca_7.gif' },
			{ id: 'calc8', 		src: 'images/calc/ca_8.gif' },
			{ id: 'calc9', 		src: 'images/calc/ca_9.gif' },
			
			{ id: 'bulle1', 		src: 'images/bulle/1.gif' },
			{ id: 'bulle2', 		src: 'images/bulle/2.gif' },
			{ id: 'bulle3', 		src: 'images/bulle/3.gif' },
			{ id: 'bulle4', 		src: 'images/bulle/4.gif' },
			{ id: 'bulle5', 		src: 'images/bulle/5.gif' },
			{ id: 'bulle6', 		src: 'images/bulle/6.gif' },
			{ id: 'bulle7', 		src: 'images/bulle/7.gif' },
			
			{ id: 'partners1', 		src: 'images/partners/alptis.gif' },
			{ id: 'partners2', 		src: 'images/partners/andac.gif' },
			{ id: 'partners3', 		src: 'images/partners/apicil.gif' },
			{ id: 'partners4', 		src: 'images/partners/april.gif' },
			{ id: 'partners5', 		src: 'images/partners/asaf.gif' },
			{ id: 'partners6', 		src: 'images/partners/aviva.gif' },
			{ id: 'partners7', 		src: 'images/partners/swiss.gif' }
		],
		modules:		[
			new $e.ProjetMutuelle( { id: 'toto' } )
		]
	} );
 });
