(function($, undefined){
	$(window).load(function(){

		$slideshow = $('#theme-backgrounds');

		$slideshow.cycle({
			fx : 'scrollHorz',
			timeout : 10000,
			pagerAnchorBuilder : function(i, DOMelement){
				return $('#theme-nav').find('li:eq('+i+')');
			},
			pager : '#theme-nav',
			activePagerClass : 'active',
			pauseOnPagerHover : true,
			before : function(curSlide, nextSlide){
				var id = $(nextSlide).attr('id');
				$('html').unbind('mousemove.parallax-biological mousemove.parallax-buildings mousemove.parallax-energy');

				// BIOLOGICAL
				if(id=="theme-background-biological"){
					$('#theme-background-biological .layers').parallax({
						eventID : 'parallax-biological',
						elements : [
							{
								selector : '#theme-background-biological li.trees',
								properties : {
									x: {
										'background-position-x': {
											initial: 50,
											multiplier: 0.03
										}
									},
									y: {
										'background-position-y': {
											initial: 0,
											multiplier: 0.01,
											invert : true,
											max : 0
										}
									}
								}
							},
							{
								selector : '#theme-background-biological li.grass',
								properties : {
									x: {
										'background-position-x': {
											initial: 0,
											multiplier: 0.01,
											invert : true
										}
									}
								}
							},
							{
								selector : '#theme-background-biological li.sheep1',
								properties : {
									x: {
										left: {
											initial: -9,
											multiplier: 0.002,
											invert : true,
											unit: '%'
										}
									},
									y: {
										bottom: {
											initial: 0,
											multiplier: 0.001,
											unit : '%'
										}
									}
								}
							},
							{
								selector : '#theme-background-biological li.sheep2',
								properties : {
									x: {
										left: {
											initial: -17,
											multiplier: 0.003,
											invert : true,
											unit: '%'
										}
									},
									y: {
										bottom: {
											initial: 0,
											multiplier: 0.001,
											unit : '%'
										}
									}
								}
							},
							{
								selector : '#theme-background-biological li.sheep3',
								properties : {
									x: {
										left: {
											initial: 11,
											multiplier: 0.0015,
											unit: '%'
										}
									},
									y: {
										bottom: {
											initial: 0,
											multiplier: 0.001,
											unit : '%'
										}
									}
								}
							},
							{
								selector : '#theme-background-biological li.deer1',
								properties : {
									x: {
										left: {
											initial: -35,
											multiplier: 0.004,
											invert : true,
											unit: '%'
										}
									},
									y: {
										bottom: {
											initial: 0,
											multiplier: 0.001,
											unit : '%'
										}
									}
								}
							},
							{
								selector : '#theme-background-biological li.deer2',
								properties : {
									x: {
										left: {
											initial: -42,
											multiplier: 0.0023,
											invert : true,
											unit: '%'
										}
									},
									y: {
										bottom: {
											initial: 0,
											multiplier: 0.001,
											unit : '%'
										}
									}
								}
							},
							{
								selector : '#theme-background-biological li.bird1',
								properties : {
									x: {
										left: {
											initial: -53,
											multiplier: 0.042,
											invert : true,
											unit: '%'
										}
									},
									y: {
										top: {
											initial: 15,
											multiplier: 0.03,
											unit : '%'
										}
									}
								}
							},
							{
								selector : '#theme-background-biological li.bird2',
								properties : {
									x: {
										left: {
											initial: -56,
											multiplier: 0.05,
											invert : true,
											unit: '%'
										}
									},
									y: {
										top: {
											initial: 15,
											multiplier: 0.03,
											unit : '%'
										}
									}
								}
							},
							{
								selector : '#theme-background-biological li.bird3',
								properties : {
									x: {
										left: {
											initial: -48,
											multiplier: 0.06,
											invert : true,
											unit: '%'
										}
									},
									y: {
										top: {
											initial: 20,
											multiplier: 0.03,
											unit : '%'
										}
									}
								}
							}
						]
					});
				}

				// BUILDINGS
				if(id=="theme-background-buildings"){
					$('#theme-background-buildings .layers').parallax({
						eventID : 'parallax-buildings',
						elements : [
							// building 1
							{
								selector : '#theme-background-buildings li.building-1',
								properties : {
									x : {
										'background-position-x': {
											initial: 0,
											multiplier: 0.002,
											invert: true,
											unit : '%'
										}
									},
									y : {
										'background-position-y': {
											initial: -1,
											multiplier: 0.05,
											invert : true,
											max : -1
										}
									}
								}
							},
							// building 2
							{
								selector : '#theme-background-buildings li.building-2',
								properties : {
									x: {
										'background-position-x': {
											initial: 0,
											multiplier: 0.004,
											invert: true,
											unit : '%'
										}
									},
									y: {
										'background-position-y': {
											initial: -1,
											multiplier: 0.01,
											invert : true,
											max : -1
										}
									}
								}
							},
							// building 3
							{
								selector : '#theme-background-buildings li.building-3',
								properties : {
									x: {
										'background-position-x': {
											initial: 0,
											multiplier: 0.008,
											invert : true,
											unit : '%'
										}
									},
									y: {
										'background-position-y': {
											initial: -1,
											multiplier: 0.03,
											invert : true,
											max : -1
										}
									}
								}
							},
							// boy
							{
								selector : '#theme-background-buildings li.boy',
								properties : {
									// left/right movement
									x: {
										left: {
											initial: 32,
											multiplier: 0.0035,
											unit : '%'
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.007
										}
									}

								// end properties
								}
							},
							// woman-walking
							{
								selector : '#theme-background-buildings li.woman-walking',
								properties : {
									// left/right movement
									x: {
										left: {
											initial: 34,
											multiplier: 0.003,
											unit : '%'
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.007
										}
									}

								// end properties
								}
							},
							// man-walking
							{
								selector : '#theme-background-buildings li.man-walking',
								properties : {
									// left/right movement
									x: {
										left: {
											initial: 25,
											multiplier: 0.002,
											unit : '%'
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.007
										}
									}

								// end properties
								}
							},
							// man-jogging
							{
								selector : '#theme-background-buildings li.man-jogging',
								properties : {
									// left/right movement
									x: {
										left: {
											initial: 13,
											multiplier: 0.01,
											unit : '%'
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.007
										}
									}

								// end properties
								}
							},
							// cyclist
							{
								selector : '#theme-background-buildings li.cyclist',
								properties : {
									// left/right movement
									x: {
										left: {
											initial: -43,
											multiplier: 0.03,
											invert : true,
											unit : '%'
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.007
										}
									}
								// end properties
								}
							},
							// woman-walking-right
							{
								selector : '#theme-background-buildings li.woman-walking-right',
								properties : {
									// left/right movement
									x: {
										left: {
											initial: -49,
											multiplier: 0.004,
											invert : true,
											unit : '%'
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.007
										}
									}
								// end properties
								}
							}
						]
					});
				}

				// ENERGY
				if(id=="theme-background-energy"){
					$('#theme-background-energy .layers').parallax({
						eventID : 'parallax-energy',
						elements : [
							// wavesBottom
							{
								selector : '#theme-background-energy li.wavesBottom',
								properties : {
									x : {
										'background-position-x': {
											initial: 0,
											multiplier: 0.08,
											invert: true
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.02,
											max : 20,
											invert : true
										}
									}
								}
							},
							// bulbsLeft
							{
								selector : '#theme-background-energy li.bulbsLeft',
								properties : {
									x : {
										left: {
											initial: 6,
											multiplier: 0.003,
											unit : '%'
										}
									},
									y : {
										bottom : {
											initial : 30,
											multiplier : 0.04
										}
									}
								}
							},
							// bulbsRight
							{
								selector : '#theme-background-energy li.bulbsRight',
								properties : {
									x : {
										left: {
											initial: -30,
											multiplier: 0.015,
											unit : '%',
											invert : true
										}
									},
									y : {
										bottom : {
											initial : 20,
											multiplier : 0.01
										}
									}
								}
							},
							// wavesTop
							{
								selector : '#theme-background-energy li.wavesTop',
								properties : {
									x : {
										'background-position-x': {
											initial: -300,
											multiplier: 0.1
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.01,
											max : 0
										}
									}
								}
							}
						]
					});
				}

				// CLIMATE CHANGE
				if(id=="theme-background-climate"){
					$('#theme-background-energy .layers').parallax({
						eventID : 'parallax-energy',
						elements : [
							// sun
							{
								selector : '#theme-background-climate li.sun',
								properties : {
									x : {
										right : {
											initial : -7,
											multiplier : 0.001,
											unit : '%'
										}
									},
									y : {
										top : {
											initial : -2,
											multiplier : 0.015,
											unit : '%',
											max : 0
										}
									}
								}
							},
							// trees1
							{
								selector : '#theme-background-climate li.trees1',
								properties : {
									x : {
										left : {
											initial : 5,
											multiplier : 0.006,
											unit : '%'
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.01,
											max : 0
										}
									}
								}
							},
							// trees2
							{
								selector : '#theme-background-climate li.trees2',
								properties : {
									x : {
										left : {
											initial : 5,
											multiplier : 0.003,
											unit : '%'
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.02,
											max : 0
										}
									}
								}
							},
							// tree1
							{
								selector : '#theme-background-climate li.tree1',
								properties : {
									x : {
										left : {
											initial : -33,
											multiplier : 0.0018,
											unit : '%',
											invert : true
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.01,
											max : 0
										}
									}
								}
							},
							// tree2
							{
								selector : '#theme-background-climate li.tree2',
								properties : {
									x : {
										left : {
											initial : 40,
											multiplier : 0.005,
											unit : '%'
										}
									},
									y : {
										bottom : {
											initial : 0,
											multiplier : 0.005,
											max : 0,
											invert : true
										}
									}
								}
							}
						]
					});
				}
			}
		});






		var themesOriginalXY = {
			x : $('#themes').position().left,
			y : $('#themes').position().top
		};

		$('#themes').dragMe().bind('dblclick', function(){
			$(this).animate({
				left : themesOriginalXY.x+'px',
				top : themesOriginalXY.y+'px'
			},
			{
				easing : 'easeOutElastic',
				duration : 700
			});
		});


	});
})(jQuery);
