var SungevitySite = {
	basePath: null,
	onReady: function() {
	
	
		// Set base path
		SungevitySite.basePath = document.location.protocol + '//' + document.location.host;
		
		for (var selector in this.elements) {
			var $elms = $(selector);
			
			if ($elms.size() > 0) {
				this.elements[selector]($elms);
			}
		}
	},

	
	
	elements: {
	

		
		'form':function($elms){
			//$('form:first *:input[type!=hidden]:first').focus();  //set focus to first form on first element
		},
		
		'#IquoteSelector': function ($elms) {
			
			var submitForm = function() {
				var act = $elms.attr('action').replace('$$$', $('select', $elms).val());
				$elms.attr('action', $elms.attr('action').replace('$$$', $('select', $elms).val()));
				$elms.submit();
			};
			
			$('select', $elms).change(submitForm);
			$('div.submit', $elms).hide();
		},
		
		
		'#UserLoginForm':function($elms){
			$('#UserEmail', $elms).focus();
		},
	
		'#IquoteEnterDetailsForm': function($elms) {
			
			var isShortSubFormVisible = ($('#ElectricityUsageLongSubForm .electricity_usage[value!=""]').length == 0);
			
			var updatedUsageFields = function(e) {
				if (isShortSubFormVisible) {
					var $toShow = $('#ElectricityUsageShortSubForm');
					$('.show-long-subform', $elms).fadeIn();
				}
				else {
					var $toShow = $('#ElectricityUsageLongSubForm');
					$('.show-short-subform', $elms).fadeIn();
				}
				
				if ($('#QuoteEstimateKw:checked', $elms).attr('value') == 1) {
					$('.electricity_usage', $elms).attr("disabled", "true").addClass('disabled');
					$('.electricity_usage', $elms).attr("value", "");
				}
				else {
					$('.electricity_usage', $toShow).attr("disabled", false).removeClass('disabled');
				}
			}
			
			var toggleUsageSubForms = function(e) {
				isShortSubFormVisible = !isShortSubFormVisible;
				updateUsageSubForms(500);
				
				e.preventDefault();
				e.stopPropagation();
				return true;
			}
			
			var updateUsageSubForms = function(animDuration) {
				
				if (isShortSubFormVisible) {
					var $toHide = $('#ElectricityUsageLongSubForm');
					var $toShow = $('#ElectricityUsageShortSubForm');
				}
				else {
					var $toHide = $('#ElectricityUsageShortSubForm');
					var $toShow = $('#ElectricityUsageLongSubForm');
					
					//	Copy month usage into bigger list
					var month = parseInt($('#QuoteElectricityUsageMonth').val());
					var monthIndex = month-1;
					if ($('#QuoteElectricityUsageMonthUsage').val() > 0){
						$('#QuoteElectricityUsage'+monthIndex).val($('#QuoteElectricityUsageMonthUsage').val())
					}
				}
				
				if (animDuration == null) {
					animDuration = 0;
				}
				
				//	Animate - but prevent glitchy display of the links during animation
				$('.show-long-subform, .show-short-subform', $elms).hide();
				$('.electricity_usage', $elms).attr('disabled', false).removeClass('disabled');
				$toHide.slideUp(
					animDuration, 
					function() { 
						$toShow.slideDown(
							animDuration, 
							function() {
								updatedUsageFields();
							}
						);  
					} 
				);
				
			}
			
			updateUsageSubForms(0);
			
			$('#QuoteEstimateKw', $elms).bind('click', updatedUsageFields);
			$('.show-long-subform, .show-short-subform', $elms).bind('click', toggleUsageSubForms);
			
		},

		'.billing_address': function($elms){
			$('.billing_address').hide();
		},
		
		/*EDIT FIGURES PAGE*/
		'.edit_figures': function($elms){
				
				
				/*Define function to clear value*/
				var return_default_value_on_edit_page = function($elms){
						/*Fill zero if no value in the box*/
						if ($('#IquoteEditForm  input[id*="electricity_usage"]', $elms).val() == ""){
							$('#IquoteEditForm  input[id*="electricity_usage"]', $elms).val(0.00);
						}
						//total
						if ($('#IquoteEditForm #QuoteElectricityUsage', $elms).val() == ""){
							$('#IquoteEditForm #QuoteElectricityUsage', $elms).val(0.00);
						}
				};				

				
				//Fill default value
				return_default_value_on_edit_page($elms);
				
				var updateElectricityUsageTotal = function() {
					var total = 0;
					var num_months_entered = 0;
					var average_monthly_usage = 0;
					$('#IquoteEditForm input[id^="QuoteElectricityUsage"]', $elms).each(
						function() {
							var value = parseFloat($(this).val());
							
							if (value==0) {
								$(this).val('');
							}else if (!isNaN(value) && value>0 && value!='') {
								num_months_entered++;
								total += value;
							}
						}
					);
					average_monthly_usage = Math.round(total / num_months_entered);
					
					$('#QuoteAverageElectricityUsage',$elms).val(average_monthly_usage);
				}
		
				/*On change, find total*/
				$('#IquoteEditForm input[id^="QuoteElectricityUsage"]', $elms).bind('change',function(e){
						
						if (($(this).val() !="") && (isNaN($(this).val()))){
							alert("Please enter a valid number");
							e.focus();
							//$(this).val("0").focus();
							e.stopPropagation();
							e.preventDefault();
							return false;
						}
						else{
							updateElectricityUsageTotal();
							return true;
						}
				});	
				
				updateElectricityUsageTotal();
		},	
		
		//iQuote: Thank you page.
		'#UserHowDidYouHear': function ($elms) {
			$('#UserHowDidYouHear').bind('change', function(e){
				
				var value = $('#UserHowDidYouHear').attr('value');
				if (value=="other"){
					$("#you_hear_from_other").css("display", "");
					$("#you_hear_from_other input:first").focus();			
				}
				else if (value=='referal') {
					$("#you_hear_from_other").css("display", "");
					$("#you_hear_from_other input:first").focus();	
				}
				else if (value=='referred_by_consultant') {
					$("#you_hear_from_other").css("display", "");
					$("#you_hear_from_other input:first").focus();	
				} 
				else {
					$("#you_hear_from_other").css("display", "none");
				}
			});
			
			
			
			/*When click back*/
			if (  	($('#UserHowDidYouHear').attr('value')=="other") ||  
					($('#UserHowDidYouHear').attr('value')=="referal") ||
					($('#UserHowDidYouHear').attr('value')=="referred_by_consultant")
				)
			{
					$("#you_hear_from_other").css("display", "");
			}
			
		},
		
 
	
		'#QuoteAddress': function($elms) {
			
			var $QuoteAddress = $elms;
			
			if ($elms.attr('type') == 'hidden') {
				return;
			}
			
			var context = ($('.home-showcase').length > 0) ? 'home' : 'widget';
			
			//	Set up autocompletion-style input for addresses
			var options = {
				url: '/virtualearth/find_address',
				minChars: (context == 'home') ? 10 : 2,
				matchSubset: false,
				matchContains: true,
				mustMatch: false,
				noMatchRegex: /No results found/,
				requestMatchRegex: /^(?=.*\d)([^\s]*)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/, // 4 words, and one digit present
				hideOnBlur: true, //stops user from clicking outside the dropdown and hiding list
				width: '', // allows width to be set from CSS
				resultsClass: (context == 'home') ? 'ui-autocomplete-results' : 'ui-autocomplete-results-narrow'
			}
			
			if ($.browser.msie) {
				var ieVersion = $.browser.version.charAt(0);
				options.resultsClass += ' ' + options.resultsClass + '-ie' + ieVersion; 
			}
			
			//	Init widget
			$QuoteAddress.autocomplete(options);
			
			//	Update styles of class when results list is showing
			$QuoteAddress.bind('autocompleteshow',
				function() {
					$(this).parents('.enter_address').addClass('enter_address_active');
					$(this).parents('.enter_address_small').addClass('enter_address_small_active');
				}
			).bind('autocompletehide',
				function() {
					$(this).parents('.enter_address').removeClass('enter_address_active');
					$(this).parents('.enter_address_small').removeClass('enter_address_small_active');
				}
			);
			
			var userHasSelectedAutocompleteOption = false;
			var hasSingleResult = false;
			var singleResult = null;
			
			//	Disable form submit
			$('#IquoteEnterAddressForm').bind("submit", function(e) {
					
					if (userHasSelectedAutocompleteOption) {
						return true;
					} else if (hasSingleResult) {
						$QuoteAddress.val(singleResult);
						return true;
					}
					else {
						e.preventDefault();
						e.stopPropagation();
						return false;
					}
				}
			);
			
			//	Re-enable form submit if matches found
			$QuoteAddress.bind('result',
				function(event, data, formatted) {
				
					hasSingleResult = (data.length == 1) && (data[0].value) && !(data[0].value.match(options.noMatchRegex));
										
					if (!formatted || formatted.match(options.noMatchRegex)) {
						userHasSelectedAutocompleteOption = false;
						if (hasSingleResult) {
							$('.ui-autocomplete-results > ul > li:first').addClass('ui-complete-over');;
							singleResult = data[0].value;
						}
						else {
							$('.ui-autocomplete-even.ui-autocomplete-over').unbind();
							userHasSelectedAutocompleteOption = false;
						}
					}
					else if (formatted && formatted.length > 1) {
						userHasSelectedAutocompleteOption = true;
					}
					
				}
			);
			
			
			//	Preload related images
			$QuoteAddress.after("<div class='ui-autocomplete-preload-images'/>");
			
			
			//	Set prompt text to include a space
			var promptText = $QuoteAddress.val();
			if (promptText.charAt(0) != ' ') {
				promptText = ' ' + promptText;
				$QuoteAddress.val(promptText);
			}
			
			//	Move selection caret to beginning of text field
			if ($QuoteAddress.get(0).selectionStart) {	// Firefox
				$QuoteAddress.get(0).selectionStart = 0;
				$QuoteAddress.get(0).selectionEnd = 0;
				$QuoteAddress.focus();
			}
			else if (document.selection) { // IE
				$QuoteAddress.focus();
				var selRange = document.selection.createRange();
				selRange.moveStart('character', -$QuoteAddress.val().length);
				selRange.moveEnd('character', 0);
				selRange.select();
			}
			else {
				$QuoteAddress.focus();
			}
			
			
			// Clear prompt text on key press
			var clearPromptText = function() {
				if ($QuoteAddress.attr('value') == promptText){
					$QuoteAddress.val("");
				}							
				return true;
			}
			$QuoteAddress.bind('keydown', clearPromptText).bind('mousedown', clearPromptText);
						
			$QuoteAddress.bind('blur',function(e){
				if ($QuoteAddress.attr('value') == ""){
					$QuoteAddress.hide().val(promptText).fadeIn(500);
				}
				e.stopPropagation();
				e.preventDefault();
				return false;
			});	
			
			$('#solar_quote_widget_form_bttn', $elms).bind('click', function(e){
				if ($QuoteAddress.attr('value') == promptText){
					
					$QuoteAddress.val("");
					$QuoteAddress.focus();
					e.stopPropagation();
					e.preventDefault();
					return false;
				}
			});
			
		},
	
			
		//IQUOTE PAGE 
		'#my_iquote': function ($elms) {
				
			var activateDefaultSizedSystem = function(index) {

				/*SIZEDSYSTEM HYPER LINK*/
				//Switch sizedSystem bar back to normal (a link)
				$('#package_list .selected .package_title', $elms).toggleClass('nonactive');
				/*SIZEDSYSTEM HYPER LINK*/
			
				/*SIZEDSYSTEM BAR*/
				//	Remove active class from all system 'bar' buttons
				$('#package_list > ul > li').removeClass('selected'); //.children('a').show();
				//	Add active class
				$('#package_list > ul > li').eq(index).addClass('selected'); //.children('a').hide();
				/*SIZEDSYSTEM BAR*/
				

				/*ROOF SNAPSHOT*/
				//Hide all panels
				$('.image .roof_snapshot', $elms).hide();
				//	Show the current panel
				$('.image .roof_snapshot', $elms).eq(index).fadeIn(500);
				/*ROOF SNAPSHOT*/				
				
				/*SET PANEL*/
				//Hide all panels
				$('.sizedSystem .sizedSystemPanel', $elms).removeClass('activeSizedSystemPanel');
				//	Hide all panels first
				$('.sizedSystem', $elms).removeClass('activeSizedSystem');
				//	Show the current panel
				$('.sizedSystem', $elms).eq(index).addClass('activeSizedSystem');
				/*SET PANEL*/


				/*SHOW ACTIVE SIZEDSYSTEM BAR*/
				//Show correct active bar
				$('#package_list .selected .package_title', $elms).toggleClass('nonactive'); //.eq(0).removeClass('nonactive').addClass('nonactive');
				/*SHOW ACTIVE SIZEDSYSTEM BAR*/


				
				/*ANIMATE SOLAR STATUS BAR*/
				//	Hide all percentage panel
				$('.utility_balance_bar', $elms).removeClass('activePercentage');
				
				/*FADE IN NEW GRAPH - */
				$('#net_cost_graph').hide();
				$('#net_cost_graph').fadeIn('slow');
				
				
				$('#payment_vs_savings .content').hide();
				$('#payment_vs_savings .content').fadeIn('900000');
				
				
				//animate from bg 95% to a certain amount
				$pos = $('.utility_balance_bar', $elms).eq(index).attr("bg_bill_reduction");
				// alert($pos);
				
				$('.utility_balance_bar', $elms).removeAttr("style"); 		//Remove style first
				$('.utility_balance_bar', $elms).css("background-position", "95% 50%"); //default bg: left most or solar ~= 10%
				$('.utility_balance_bar', $elms).eq(index).addClass('activePercentage');
				$('.utility_balance_bar', $elms).animate({	backgroundPosition: $pos},1000);
							
				/*ANIMATE SOLAR STATUS BAR*/
				 
				/*ORDER SHOWCASE*/
				$('#order_showcases > li').hide().eq(index).show();

				/*SHOW DEFAULT PANEL*/				
				// Hide all the first panel
				

				$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).slideUp("slow").removeClass('activeSizedSystemPanel');
				
				
				//Show the first panel of the active sizedSystem
				$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).eq(0).addClass('activeSizedSystemPanel').slideDown("slow").fadeIn("fast");
				/*SHOW DEFAULT PANEL*/

				/*bind all tab for panel*/
				bindActivePanelTabLink();								
			}
						
			
			
			var activateSizedSystem = function(index) {

				/*SIZEDSYSTEM HYPER LINK*/
				//Switch sizedSystem bar back to normal (a link)
				$('#package_list .selected .package_title', $elms).toggleClass('nonactive');
			
			
			
				/*SIZEDSYSTEM BAR*/
				//	Remove active class from all system 'bar' buttons
				$('#package_list > ul > li').removeClass('selected'); //.children('a').show();
				//	Add active class
				$('#package_list > ul > li').eq(index).addClass('selected'); //.children('a').hide();
				
				/*ROOF SNAPSHOT*/
				//Hide all panels
				$('.image .roof_snapshot', $elms).hide();
				//	Show the current panel
				$('.image .roof_snapshot', $elms).eq(index).fadeIn('slow');
				/*ROOF SNAPSHOT*/	
/*
				//Hide all panels
				$('.sizedSystem .sizedSystemPanel', $elms).removeClass('activeSizedSystemPanel');
				//	Hide all panels first
				$('.sizedSystem', $elms).removeClass('activeSizedSystem');
				//	Show the current panel
				$('.sizedSystem', $elms).eq(index).addClass('activeSizedSystem');
*/

				/*SHOW ACTIVE SIZEDSYSTEM BAR*/
				//Show correct active bar
				$('#package_list .selected .package_title', $elms).toggleClass('nonactive'); //.eq(0).removeClass('nonactive').addClass('nonactive');
				//$('#package_list .selected .package_title', $elms).eq(1).removeClass('nonactive');
				



				
				/*ANIMATE SOLAR BAR*/
				//Hide all bars
				$('.utility_balance_bar', $elms).removeClass('activePercentage');
				//Performing to animate from the current background to new solar amount
				$pos = $('.utility_balance_bar', $elms).eq(index).attr("bg_bill_reduction");	//New position
				$('.utility_balance_bar', $elms).eq(index).addClass('activePercentage');
				$('.utility_balance_bar', $elms).animate({backgroundPosition: $pos},1000); 
				/*ANIMATE SOLAR BAR*/
				

				/*ORDER SHOWCASE*/
				$('#order_showcases > li').hide().eq(index).show();
				

				// Hide all the first panel
				//$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).slideUp("slow").removeClass('activeSizedSystemPanel');
				//Show the first panel of the active sizedSystem
				//$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).eq(0).addClass('activeSizedSystemPanel').slideDown("slow").fadeIn("fast");


				/*ANIMATE PANEL*/
				/*Display first panel*/
				// 	
				/*	
				$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel div.content', $elms).slideUp(1000, function(){
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).removeClass('activeSizedSystemPanel');
						
						//	Hide all panels first
						$('.sizedSystem', $elms).removeClass('activeSizedSystem');
						//	Show the current panel
						$('.sizedSystem', $elms).eq(index).addClass('activeSizedSystem');
								
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).eq(0).addClass('activeSizedSystemPanel');
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel div.content', $elms).slideDown(1000, function(){
							bindActivePanelTabLink();
						});
				});
				*/
				$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel div.content .details .detail_wrapper', $elms).fadeOut('fast', function(){
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).removeClass('activeSizedSystemPanel');
						
						//	Hide all panels first
						$('.sizedSystem', $elms).removeClass('activeSizedSystem');
						//	Show the current panel
						$('.sizedSystem', $elms).eq(index).addClass('activeSizedSystem');
								
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).eq(0).addClass('activeSizedSystemPanel');
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel div.content .details .detail_wrapper', $elms).fadeIn('fast', function(){
							bindActivePanelTabLink();
						});
				});										
			}
			
			
			
			
			
			
			
				
			
			
			
		
				/*REBIND LINK AFTER CLICKING ON THE BAR*/
				var rebindSizedSystem = function(){
						$('#package_list > ul > li > a', $elms).bind(
							'click',
							function(evt) {
													
								var index = $('#package_list > ul > li', $elms).index($(this).parent());
								activateSizedSystem(index);
								
						
								
									
								rebindSizedSystem();				
										
								evt.stopPropagation();
								evt.preventDefault();
								return false;
							}
						);
				}


				/*REBIND LINK AFTER YOUR CLICK*/
				var bindActivePanelTabLink = function(){
							$('.sizedSystemPanel.activeSizedSystemPanel  .nav > ul > li > a').unbind();
							$('.sizedSystemPanel.activeSizedSystemPanel  .nav > ul > li > a').bind(
								'click',
								function(evt) {
							
									var index = $('.sizedSystemPanel.activeSizedSystemPanel .nav > ul > li').index($(this).parent());
							
									activateSizedSystemPanel(index);
										
									evt.stopPropagation();
									evt.preventDefault();
									return false;
								}
					);
				}



	
			//To activate a panel
			var activateSizedSystemPanel = function(index) {
				// Hide all the first panel


				/*content slideup*/
				/*$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel div.content', $elms).slideUp(1000, function(){
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).removeClass('activeSizedSystemPanel');
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).eq(index).addClass('activeSizedSystemPanel');
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel div.content', $elms).slideDown(1000, function(){
							bindActivePanelTabLink();
						});
				});*/
				/**/
				
				/*content slideup*/
			//	$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel div.content .details', $elms).fadeOut(1000);
				$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel div.content .details .detail_wrapper', $elms).fadeOut('fast', function(){
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).removeClass('activeSizedSystemPanel');
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel', $elms).eq(index).addClass('activeSizedSystemPanel');
					//	$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel div.content .details', $elms).fadeIn(1000);
						$('.sizedSystem.activeSizedSystem > div.sizedSystemPanel div.content .details .detail_wrapper', $elms).fadeIn('fast', function(){
							bindActivePanelTabLink();
							
						});
				});
				/**/
				
			}
			
			
						
						
						
			// Bind all	Bars on sizedSystem.
			$('#package_list > ul > li > div > a', $elms).bind(
				'click',
				function(evt) {
										
					var index = $('#package_list > ul > li', $elms).index($(this).parent().parent());
					
			
					activateSizedSystem(index);					
							
					evt.stopPropagation();
					evt.preventDefault();
					return false;
				}
			);
			
			
			
			/*First time: when load the page*/
			activateDefaultSizedSystem(0);
			
		}, //End my_iquote
		
		//start home gallery
		'.home-showcase': function($elms) {
			
			//	Fetch elements
			var $preview = $('.home-showcase .preview-container');
			var $imageLinks = $('.showcase-thumbs a', $elms);
			//console.log($imageLinks);
			var $images = $('img', $imageLinks);
			var $current_image = 1;
			//var $counter = $('.product-navigation .image-count', $elms);
			//var $prevLink = $('.product-navigation .previous-link', $elms);
			//var $nextLink = $('.product-navigation .next-link', $elms);
			
			//	Runtime variables
			var width = $preview.children('.img').width();
			var height = $preview.children('img').height();
			var imagesCount = $images.length;
			var activeImageIndex = 0;
			
			 if($.browser.msie && $.browser.version == 6){	
				 //ignore ie6	
			  }else{
				  $preview.everyTime(6000,function(i) {
						imgs = $imageLinks;
						showImage($(imgs).eq($current_image));
					});
			  }

			 
				
			
			//	Functions
			var init = function() {
				$images.css({'opacity': .63 });
				$images.hover(
					function() {
						$(this).stop().animate(
							{'opacity': 1},
							{'duration': 'fast'}
						);
					},
					function() {
						
						var $this = $(this);
						if ($this.parents('a.active-image').length == 0) {
							$this.stop().animate(
								{'opacity': .63},
								{'duration': 'fast'}
							);
						}
					}
				);
				
				//	Bind links
				$imageLinks.bind(
					'click', 
					function(e) {
						showImage($(this));
						e.preventDefault();
						e.stopPropagation();
						return true;
					}
				);
				/*
				$prevLink.bind(
					'click',
					function(e) {
						prevImage();
						e.preventDefault();
						e.stopPropagation();
						return true;
					}
				);
				
				$nextLink.bind(
					'click',
					function(e) {
						nextImage();
						e.preventDefault();
						e.stopPropagation();
						return true;
					}
				);
				*/
				//	Preload images
				$imageLinks.preload();
				
				//	Set initial status
				if ($imageLinks.length > 0) {
					updateStatus($imageLinks.eq(0));
				}
			};
			/*
			var nextImage = function() {
				if (activeImageIndex+1 < imagesCount) {
					activeImageIndex++;
					showImage($imageLinks.eq(activeImageIndex));
				}
			};
			
			var prevImage = function() {
				if (activeImageIndex-1 >= 0) {
					activeImageIndex--;
					showImage($imageLinks.eq(activeImageIndex));
				}
			};
			*/
			var showImage = function($imageLink) {
				$current_image = $imageLink.parent().prevAll().length;	
				
				if($current_image < imagesCount - 1){
					$current_image++;
				}else if($current_image == imagesCount - 1){
					$current_image = 0;
				}
				
				//	Clear old images
				$preview.children('img:not(img:last)').stop().remove();
				
				//	Insert new image, at 0 opacity
				$("<img style='' src='"+$imageLink.attr('href')+"' />").appendTo($preview);
				var $newImage = $preview.children('img:last').css('opacity', 0);
				
				//	Fade out old image, fade in new
				var $oldImage = $preview.children('img:first').stop().animate(
					{ 'opacity': 0 },
					'fast',
					function() {
						$newImage.animate(
							{ 'opacity': 1.0 },
							'medium'
						);
						$oldImage.remove();
					}
				);
				
				updateStatus($imageLink);
			}
			
			var updateStatus = function($imageLink) {
				//	Update counter
				activeImageIndex = $imageLinks.index($imageLink);
				//$counter.text((1+activeImageIndex)+'/'+imagesCount);
				
				//	Update highlighted thumbnail
				$imageLinks.removeClass('active-image').children('img').stop().animate(
					{'opacity': 0.78},
					{'duration': 'fast'}
				);
				$imageLink.addClass('active-image').children('img').stop().animate(
					{'opacity': 1},
					{'duration': 'fast'}
				);
			}
						
			init();
			
		}
		//ehome gallery
	},
	
	showThankYouForSigning: function(pathname){
		if( typeof(SungevitySite.onBeforeShowThankYouForSigning) == 'function' ){
			if( SungevitySite.onBeforeShowThankYouForSigning() == false) {
				return;
			}
		}
		document.location.pathname = pathname;		
	}	

}






$(document).ready(
	function()
	{
		SungevitySite.onReady();
	}
);

