var jQNC = jQuery.noConflict();


var API = ''; // init pour les 'onclick' des liens de démo
var cptHorizontal = 1;

function nextCptValue(cpt,maxi) {
	if (cpt >= maxi) cpt = 0;
	return (cpt + 1);
}
function showNextHorizontal() {
	var maxi = 4; /////
	if (cptHorizontal >= maxi) cptHorizontal = 0;
	cptHorizontal ++;
	API.show('images/home_' + cptHorizontal + '.png');
}
jQNC(document).ready(function()
{
	jQNC(".twitter-tl").tweet({
            username: "ohlalave",
            avatar_size: 0,
            count: 2,
            loading_text: "<ul><li>Cargando tweets...</li></ul>",
			template: "<strong><a href='http://www.twitter.com/ohlalave'>Ohlalave</a></strong> {text}"
        });
		
	jQNC('.tab_content').show().jScrollPane({showArrows: false}).hide();
	jQNC("ul.tabs li:first").addClass("active").show();
	jQNC(".tab_content:first").show();

	jQNC("ul.tabs li").click(function()
       {
		jQNC("ul.tabs li").removeClass("active");
		jQNC(this).addClass("active");
		jQNC('.tab_content').show().jScrollPane({showArrows: false}).hide();

		var activeTab = jQNC(this).find("a").attr("href");
		jQNC(activeTab).fadeIn();
		return false;
	});
	
	jQNC.fn.hoverscroll.params = jQNC.extend(jQNC.fn.hoverscroll.params, {
	vertical : true,
	width: 360,
	height: 693,
	arrows: false
});

jQNC('.groupfade').slidy({
    animation:  'fade',
    height:     179,
    width:      227,
	time:       5000
});


API = jQNC('#myImageZone').transitionBox({
		"width" : 560, /////
		"height" : 360, /////
		"duration" : 300, /////
		"effect" : "zoom"
	}).show('images/home_1.png','zoom',300, "linear"); ///// affichage au chargement


jQNC('#sigue').click(function(){
	showNextHorizontal();
	return false;
	});

setInterval(function(){jQNC("#sigue").click()},5000);

jQNC("#grupos .grupo").hover(function() {
		jQNC(this)
			.stop(true, false)
			.animate({
				width: 340,
				boxShadow: '0 0 20px'
			}, 'fast');
		jQNC("div.img", this)
			.stop(true, false)
			.animate({
				opacity: 1,
				"-moz-opacity": 1
			}, 'fast');
	}, function() {
			jQNC(this).stop(true, false).animate({
				width: 319,
				boxShadow: '0 0 10px'
		}, 'fast');
			jQNC("div.img", this).stop(true, false).animate({
				opacity: 0.6,
				"-moz-opacity": 0.6
			}, 'fast');
	});

// Generate hoverscroll with overridden default parameters
jQNC('#grupos').hoverscroll();
	
	jQNC(".wwbuttons>button,.wwbuttons>a").wwbutton();

	jQNC('div.accordion> div.cont.hide').hide();
  	jQNC('div.accordion> li').click(function() {
    jQNC(this).next('div').slideToggle('fast')
    .siblings('div:visible').slideUp('fast');
	
  });
	

//HOME SCRIPT  

	var deg=0;

	/* Storing all the images into a variable */

	var images	= jQNC('#stage img').removeClass('default').addClass('animationReady');
	var dim		= { width:images.width(),height:images.height()};
	
	var cnt = images.length;
	
	/* Finding the centers of the animation container: */
	var centerX = jQNC('#stage').width()/2;
	var centerY = jQNC('#stage').height()/2 - dim.height/2;

	function rotate(step,total){
		// This function loops through all the phone images, and rotates them
		// with "step" degrees (10 in this implementation) until total has reached 0
	
		/* Increment the degrees: */
		deg+=step;
		
		var eSin,eCos,newWidth,newHeight,q;
		
		/* Loop through all the images: */
		for(var i=0;i<cnt;i++){
			
			/* Calculate the sine and cosine for the i-th image */
			
			q = ((360/cnt)*i+deg)*Math.PI/180;
			eSin		= Math.sin(q);
			eCos		= Math.cos(q);
			
			/*
			/	With the sine value, we can calculate the vertical movement, and the cosine 
			/	will give us the horizontal movement.
			*/
			
			q = (0.6+eSin*0.2);
			newWidth	= q*dim.width;
			newHeight	= q*dim.height;
			
			/*
			/	We are using the calculated sine value (which is in the range of -1 to 1)
			/	to calculate the opacity and z-index. The front image has a sine value
			/	of 1, while the backmost one has a sine value of -1.
			*/
			
			images.eq(i).css({
				top			: centerY+80*eSin,
				left		: centerX+300*eCos,
				opacity		: 0.8+eSin*0.2,
				marginLeft	: -newWidth/2,
				zIndex		: Math.round(80+eSin*50)
			}).width(newWidth).height(newHeight);
		}

		total-=Math.abs(step);
		if(total<=0) return false;
		
		// Setting the function to be run again in 40 seconds (equals to 25 frames per second):
		setTimeout(function(){rotate(step,total)},40);
	
	}
	
	// Running the animation once at load time (and moving the iPhone into view):
	rotate(10,360/cnt);
	
	jQNC('#ohlalaCarousel .previous').click(function(){
		// 360/cnt lets us distribute the phones evenly in a circle
		rotate(-10,360/cnt);
	});
	
	jQNC('#ohlalaCarousel .next').click(function(){
		rotate(10,360/cnt);
	});
	
	setInterval(function(){jQNC(".next.arrow").click()},5000)
	
	jQNC("#carousel1").CloudCarousel(		
		{			
			xPos: 600,
			yPos: 50,
			buttonLeft: jQNC("#left-but"),
			buttonRight: jQNC("#right-but"),
			altBox: jQNC("#alt-text"),
			titleBox: jQNC("#title-text"),
			autoRotate: 'yes',
			speed: 0.1,
			autoRotateDelay: 5000
		}
	);
});

	function clearText(field){
    if (field.defaultValue == field.value) {
		field.value = "";
		field.className = "active";
		}
    else if (field.value == "") {
		field.value = field.defaultValue;
		field.className = "none";
	}
	}
