$( document ).ready( function(){

		/* Screenshots */
		var i = 1;
		var images = new Array();

		var howManyImages = 11;

		var descriptions = new Array();
		descriptions[1] = "Share your story";
		descriptions[2] = "Write a blog";
		descriptions[3] = "Find great clubs";
		descriptions[4] = "Find friends";
		descriptions[5] = "Find people near you";
		descriptions[6] = "Post on our forum";
		descriptions[7] = "Browse people photos";
		descriptions[8] = "Home sweet home";
		descriptions[9] = "See who have visited you";
		descriptions[10] = "Use internal mail";
		descriptions[11] = "Check people's profiles";


		for ( i=1;i<=3;i++ ) {
				var end = false;
				while ( end==false ) {
						images[ i ] = Math.floor(Math.random()*howManyImages+1);
						if ( i == 1 ) {
								end = true;
						}
						else if ( ( i == 2 ) && ( images[ 2 ] != images[ 1 ] ) ) {
								end = true;
						}
						else if ( ( i == 3 ) && ( images[ 3 ] != images[ 2 ] ) && ( images[ 3 ] != images[ 1 ] ) ) {
								end = true;
						}
				}

				$( ".welcomeSide .welcomePic.original" ).clone(true).prependTo(".welcomeSide").addClass("tmpPic").removeClass("original");
				$( ".welcomeSide .welcomePic.tmpPic a" ).attr( "href", "/img/screenshots/0"+images[ i ]+".jpg" );
				$( ".welcomeSide .welcomePic.tmpPic a img" ).attr( "src", "/img/screenshots/0"+images[ i ]+"_t.jpg" );
				$( ".welcomeSide .welcomePic.tmpPic .description" ).html( descriptions[ images[ i ] ] );
				//$( ".welcomeSide .welcomePic.tmpPic a" ).attr( "title", descriptions[ images[ i ] ] );
				$( ".welcomeSide .welcomePic.tmpPic" ).removeClass("tmpPic");

		}
		$( ".welcomeSide .welcomePic.original a" ).attr("rel","");
		$(".welcomeSide .welcomePic a.group").fancybox();


		/* Features */

		function showFeature ( feature ) {
				var showThis = feature.attr( "class" );
				var showText = feature.text();
				var showThisObject = $( ".featuresContent ."+showThis );
				//alert ( $( ".sideFeatures li:last" ).prevAll("li").length );

				// Checking index of element and removing classes
				if ($( ".sideFeatures li.active" ).prevAll("li").length > 0 ) {
						$( ".sideFeatures li.active" ).prev("li").removeClass("noBg");
				}
				else {
						$( ".sideFeatures ul" ).removeClass("noBg");
				}
				$( ".sideFeatures li.active" ).removeClass("active");

				// Checking index of element and adding classes
				if ( feature.parent("li").prevAll("li").length > 0 ) {
						feature.parent("li").prev("li").addClass("noBg");
				}
				else {
						feature.parents("ul").addClass("noBg");
				}
				feature.parent("li").addClass("active");

				if ( !showThisObject.is( ":visible" ) && $( ".featuresContent .feature:visible").length != "" ) { //Checking if element is not already visible

						//Sliding content
						$( ".featuresContent .feature:visible").slideUp( "fast", function () {
								$( ".featuresContent h2 span" ).text(showText);
								showThisObject.slideDown("fast");
						} );
				}
				else { //First Time
						$( ".featuresContent h2 span" ).text(showText);
						//$( ".sideFeatures a[rel=default]" ).parent("li").addClass("active");
						showThisObject.slideDown("fast");
				}
		}

		showFeature( $( ".sideFeatures a[rel=default]" ) );

		$(".sideFeatures a").click(function () {
				showFeature( $( this ) );
		});

		//$(".videoPlaceholder").fancybox({
		//		'hideOnContentClick': false
		//});


		/*	facebox rel
		- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/


		$('a[rel*=faceboxVideo]').click(function () {

				jQuery.facebox( '<a href="javascript:void(0);" onClick="closeFacebox();" class="exitFacebox" id="close">Close</a><div class="clear"></div>'+'<div id="showMeVideo"><p>Please Install <a href="http://get.adobe.com/flashplayer/">Adobe Flash Player</a></p></div>' ,'wideVideo');
				var videoUrl = $(this).attr("href");
				swfobject.embedSWF("/swf/fPlayerIn.swf", "showMeVideo", "855", "480", "9.0.0","/swf/expressInstall.swf", {playList:"/views/xml/"+videoUrl+".xml"}, {wmode:"transparent"} );

		});




} );

function closeFacebox() {
		$( "#facebox .content" ).html("");
		jQuery(document).trigger('close.facebox');
}