// functions home



		 $(document).ready(function () {
			 
		
				 
		 if ($.browser.msie) {
			// internet explore whines about console.
			console = 'nothing'; 
		 }
		 
		 
		 function showSlider () {
			 var windowWidth = window.innerWidth / 2;
			var left = window.innerWidth - 978;
			var center = 978 /2 - $('.descriptionBox').outerWidth();
			left = left /2;
			var imageWidth = $('.imageBox').outerWidth();
			var descriptionWidth = $('.descriptionBox').outerWidth();
				$('.descriptionBox, .imageBox').fadeTo(0,0, function () {
					$('.descriptionBox').css({ 'margin-top': 55, 'left': '-' + left + 'px'});
					$('.imageBox').css({'right': 0, 'z-index' : -1});
					
					
					
					$('.descriptionBox').animate({'left': center, 'opacity': 1}, {duration: 1000, easing: "easeInOutCirc", complete: function () {
						//$('.imageBox').animate({'right': windowWidth - imageWidth, 'opacity': 1}, {duration: 600 ,easing: "easeInOutCirc"});
					}})
			
		});
		 }
		 
		 function changePosition () {
			  var windowWidth = window.innerWidth / 2;
			var left = window.innerWidth - 978;
			var center = 978 /2 - $('.descriptionBox').outerWidth();
			left = left /2;
			var imageWidth = $('.imageBox').outerWidth();
			var descriptionWidth = $('.descriptionBox').outerWidth();
				
					
					$('.descriptionBox').animate({'left': center, 'opacity': 1}, {duration: 0, easing: "easeInOutCirc", complete: function () {
						$('.imageBox').animate({'right': windowWidth - imageWidth, 'opacity': 1}, {duration: 0 ,easing: "easeInOutCirc"});
					}})
			
		
		 }
		 
		
		 
		 
		 //for the portfolio items
		
		$('.sideRight .portfolioItems li a')
		
		
		.mouseover(function(){
	
			$(this).find('span').stop().animate({'bottom': 0}, 300)
				
			})
		.mouseout(function(){
			$(this).find('span').stop().animate({'bottom': '-' + $(this).outerHeight(true) + 'px' }, 500)
			
			}) 
			
			
			 //for the portfolio items
		
		$('#footerCntr .followBox li a')
		
		
		.mouseover(function(){
	
			$(this).find('img').stop().animate({'margin-top': 30, 'margin-bottom': 10}, 100)
				
			})
		.mouseout(function(){
			$(this).find('img').stop().animate({'margin-top': 35, 'margin-bottom': 5}, 100)
			
			}) 
			
			
		// for the service items	
		$('.sideRight .serviceItems li')
		
		
		.mouseover(function(){
	
			$(this).stop().animate({'margin-top': 10}, 100)
				
			})
		.mouseout(function(){
			$(this).stop().animate({'margin-top': '0' }, 100)
			
			}) 
			
		
		
		$('.blockCntr').fadeTo(0,0);
		jQuery('.blockCntr').each(function(i){
		jQuery(this).delay(i*300).fadeTo(700,1,function(){
			 if ($.browser.msie) {
			 this.style.removeAttribute('filter');
			 }

		  
		 });
		});
	 });
	 
	 
	 	var letsMakeLove={ 
			// Marvin Gaye is the best
			settings: {},
			start:function () {
				
				
				this.toTop();
				this.toLeft();
				this.toRight();
				
				
			},
			breakUp:function () {
				$(this.settings.selector).html('');
			},
			
			toTop:function() {
				var sel2 = this.settings.selector;
				var img2 = this.settings.image;
				
				var i2 = 0;
				// Lets get it on!
					var p2 = $(this.settings.from);
					var position2 = p2.position();
					var width2 = p2.outerWidth();
					var delay2 = 0;	
					
				for (i2 = 0; i2 < this.settings.maxItems; i2++) {
					
					var from2 = Math.random() * width2 - 50;
					var from2 = from2 + position2.left;
					
					var toLeft2 = Math.random() *  (width2 + 100) + position2.left - 50;
					var toTop2 = (Math.random()*50) + 130;
					
					
					$(sel2).append(img2);
					$(sel2 + ' img:last').addClass('class2_' + i2);
					$(sel2 + ' .class2_' + i2).css({'position': 'absolute', 'top': '-60px', 'left': from2, 'opacity': 0 });
					
					var randomDelay2 = (Math.random() * 100) + this.settings.maxDelay;
					var delay2 = delay2 + randomDelay2;
					
					$(sel2 + ' .class2_' + i2)
					.delay(delay2)
					.fadeIn()
					.animate({'left': toLeft2, 'top': '-' + toTop2, 'opacity': (Math.random() * 0.01)+0.9}, {duration: (Math.random() * this.settings.durationMax) + 500 } )
					.fadeOut();
					 
					
					
				}
			}
			, 
			toLeft: function() {
				
				var sel3 = this.settings.selector;
				var img3 = this.settings.image;
				
				var i3 = 0;
				// Lets get it on!
					var p3 = $(this.settings.from);
					var position3 = p3.position();
					var width3 = p3.outerWidth();
					var height3 = p3.outerHeight();
					var delay3 = 0;	
					
				for (i3 = 0; i3 < (this.settings.maxItems)/2; i3++) {
					
					
					
					var from3 = (Math.random() * height3)-100;
					var from3 = from3 + position3.top;
					
					var toLeft3 = (Math.random() * position3.left)-30;
					var toTop3 = (Math.random()*30) + 130;
					
					
					$(sel3).append(img3);
					$(sel3 + ' img:last').addClass('class3_' + i3);
					$(sel3 + ' .class3_' + i3).css({'position': 'absolute', 'top': from3, 'left': position3.left - 20 , 'opacity': 0 });
					
					var randomDelay3 = (Math.random() * 100) + this.settings.maxDelay;
					var delay3 = delay3 + randomDelay3;
					
					$(sel3 + ' .class3_' + i3)
					.delay(delay3)
					.fadeIn()
					.animate({'left': toLeft3, 'top': '-' + toTop3, 'opacity': (Math.random() * 0.01)+0.9}, {duration: (Math.random() * this.settings.durationMax) + 500 } )
					.fadeOut();
					 
					
					
				}
			},
			toRight: function() {
				
				var sel = this.settings.selector;
				var img = this.settings.image;
				
				var i = 0;
				// Lets get it on!
					var p = $(this.settings.from);
					var position = p.position();
					var width = p.outerWidth();
					var height = p.outerHeight();
					var delay = 0;	
					
				for (i = 0; i < (this.settings.maxItems)/2; i++) {
					
					
					
					var from = (Math.random() * height)-100;
					var from = from + position.top;
					var test = this.settings.maxWidth - position.left - width;
					var test2 = test * Math.random();
					var test3 = test2 + position.left + width;
					
					var toLeft = test3;
					var toTop = (Math.random()*50) + 130;
					
					
					$(sel).append(img);
					$(sel + ' img:last').addClass('class_' + i);
					$(sel + ' .class_' + i).css({'position': 'absolute', 'top': from, 'left': this.settings.maxWidth - position.left , 'opacity': 0 });
					
					var test = (Math.random() * 100) + this.settings.maxDelay;
					var delay = delay + test;
					
					$(sel + ' .class_' + i)
					.delay(delay)
					.fadeIn()
					.animate({'left': toLeft, 'top': '-' + toTop, 'opacity': (Math.random() * 0.01)+0.9}, {duration: (Math.random() * this.settings.durationMax) + 500 } )
					.fadeOut();
					 
					
					
				}
			}
			
		};
	 
		var counter = 0;
		
		$('.banner_1, .banner_2').fadeTo(0,0);
		
		function nextSlide() {
			
			var windowWidth = window.innerWidth / 2;
			
			var middle = (978/2);
			var outerSpace = '-' + ((window.innerWidth -1000) /2) + 'px';
			
			switch (counter) {
				
				case 1:;
				
				letsMakeLove.settings = { selector: '.hearts', from: '.banner_1 .descriptionBox', image: '<img src="' + ROOT + 'resources/images/lovin1.png" />', durationMax: 6000, maxItems: 10, durationMin: 200, maxHeight: 300, width: '100%', maxWidth: 978, maxDelay: 400};
					
					
		
				
				$('.banner_1 .descriptionBox').css({'left': outerSpace, 'top': 60});
				;
				
				$('.banner_1 .descriptionBox').animate({'left': middle - ($('.banner_1 .descriptionBox').outerWidth()/2), 'opacity': 1}, 
				{duration: 1000,
				easing: "easeInOutCirc", 
				complete: 
					function () { 
					 letsMakeLove.start();
					$('.banner_1 .imageBox').animate({'right': middle - ($('.banner_1 .imageBox').outerWidth() - 5), 'opacity': 1, 'top': 0}, {duration: 1000, easing:"easeInOutCirc", complete: function () { }} );
					}
				});
				
				break;
				case 2:
				
				$('.banner_2 .imageBox').css({'right': outerSpace});
				$('.banner_2 .descriptionBox').css({'left': outerSpace});
				
				$('.banner_2 .descriptionBox').animate({'left': middle - $('.banner_2 .descriptionBox').outerWidth()-110, 'opacity': 1}, 
				{duration: 1000,
				easing: "easeInOutCirc", 
				complete: 
					function () { 
					$('.banner_2 .imageBox').animate({'right': middle - ($('.banner_2 .imageBox').outerWidth() - 75), 'opacity': 1}, {duration: 100, easing:"easeInOutCirc", complete:
					function () {
						$('.banner_2 .imageBox .img1').css({'padding-left': '45px', 'padding-top': '20px'});
						$('.banner_2 .imageBox .img1').animate({'width': '500px', 'padding-left': '0px', 'height': '258px', 'opacity': 1}, {duration: 800, easing:"easeInOutCirc", complete:
					function () {
						$(' .img2').css({'padding-left': '50px'});
						$(' .img2').animate({'width': '500px', 'padding-left': '0px',  'height': '258px', 'opacity': 1},{duration: 500, easing:"easeInOutCirc"});
					
						$(' .img3').css({'padding-right': '50px'});
						$(' .img3').delay(200).animate({'width': '500px', 'padding-right': '0px',  'height': '258px', 'opacity': 1}, {duration: 500, easing: "easeInOutCirc"});
						
					}})
					
					}} 
					);
					}
				});
				
		
				break;
		
			}
			// end the switch
			
			
		}
		
		function hideSlide() {
			if (counter == 2) {
				counter = 0;
							}
			
			counter ++;
			switch (counter) {
				case 1:
				letsMakeLove.breakUp();
				$('.banner_1 .imageBox, .banner_1 .descriptionBox').fadeTo(0,0);
				break;
				case 2:
				$('.banner_2 .imageBox img').removeAttr('style');
				$('.banner_2 .imageBox, .banner_2 .imageBox img, .banner_2 .descriptionBox').fadeTo(0,0);
			}
			
			
			
		}
		
		
		$(document).ready(function () {
		
	
		$(window).bind('resize', function () { 
			//makeItNice(counter);
		});
		
		function makeItNice() {
			switch(counter) 
			{
				case 2:
				$('.banner_2 .descriptionBox').css({'left': middle - $('.banner_2 .descriptionBox').outerWidth()-110});
				$('.banner_2 .imageBox').css({'right': middle - ($('.banner_2 .imageBox').outerWidth() - 75)});
				break;
				default:
				console.log(counter);
				$('.banner_' + counter + ' .imageBox').css( {'right': (978/2) - ($('.banner_' + counter +' .imageBox').outerWidth()) - 5});
				break;
				
			}
		}
		
		// cycle plugin :)
		
		
		
		 $('.slider').cycle({ 
			fx:     'fade',
			after:	onAfter,
			before: onBefore,
			
			speed:  170,
			timeout: 10000,
			 startingSlide: 2
			 
		});
		
		
		
		function onBefore () {
			hideSlide();
		}
		
		function onAfter () {
			nextSlide();
		}
		
	
		
	 });
	 
