$(function () {
	/*
	$('.top-menu ul li').hover(function(){
			
			$('ul',this).hide().delay(20).slideDown('normal','linear');
		},function(){
			$('ul',this).delay(20).slideUp('normal','linear');
			})
	*/
	$('.resultLists').hover(function(){
			$(this).addClass('resultsListsHover');
		},function(){
			$(this).removeClass('resultsListsHover');
			}).click(function(){
			$(this).toggleClass('resultsListsClick');
		});
	$('img').load(function(){
		$('.sidebar').height($('.content').height());
	});
	
	
	$('body').append('<div id="dialog-form" title="SEND TO FRIEND"><p class="validateTips">All form fields are required.</p><form action="'+url+'ajax/sendtofriend" method="post" class="senddialog"><input type="hidden" name="flag" value="sendtofriend"/><input type="hidden" name="ss_sendtofriend" value=""/><fieldset><p><label for="sendname">Your name</label><input type="text" name="sendname" id="sendname" value="" class="text ui-widget-content ui-corner-all" /></p><p><label for="sendemail">Your Email</label><input type="text" name="sendemail" id="sendemail" value="" class="text ui-widget-content ui-corner-all" /></p><p><label for="friendname">Your Friend</label><input type="text" name="friendname" id="friendname" value="" class="text ui-widget-content ui-corner-all" /></p><p><label for="sendemail">Friend Email</label><input type="text" name="friendemail" id="friendemail" value="" class="text ui-widget-content ui-corner-all" /></p><p><label for="sendcomment">Comment</label><textarea id="sendcomment" name="sendcomment" rows="5" cols="30" class="text ui-widget-content ui-corner-all"></textarea></p></fieldset></form></div>');
	
	
	$.get(url+'ajax/getSS',function(res){
			$('input[name="ss_sendtofriend"]').val(res.ss);
			
		});
	
	

	var email_pattern = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
	
	var subscribe_sent = false;
	var sendemail = $( "#sendemail" ),
		sendname = $( "#sendname" ) ,
		friendemail = $( "#friendemail" ),
		friendname = $( "#friendname" ) ,
		sendcomment = $( "#sendcomment" ),
			allFields = $( [] ).add( sendemail ).add( sendname ).add( friendemail ).add( friendname ).add( sendcomment ),
			tips = $( ".validateTips" ),
			sent_subscrib = false
			;

		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}

		function checkLength( o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				updateTips( "Length of " + n + " must be between " +
					min + " and " + max + "." );
				return false;
			} else {
				return true;
			}
		}

		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}
		
		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 500,
			width: 450,
			modal: true,
			buttons: {
				"SEND": function() {
					var bValid = true;
					allFields.removeClass( "ui-state-error" );
					
					bValid = bValid && checkLength( sendname, "Your Name", 2, 30 );
					
					bValid = bValid && checkLength( sendemail, "Your Email", 6, 80 );

					bValid = bValid && checkRegexp( sendemail, email_pattern, "eg. email@domain.com" );
					
					bValid = bValid && checkLength( friendname, "Your Friend Name", 2, 30 );
					
					bValid = bValid && checkLength( friendemail, "Your Friend Email", 6, 80 );

					bValid = bValid && checkRegexp( friendemail, email_pattern, "eg. email@domain.com" );
					
					bValid = bValid && checkLength( sendcomment, "Comment", 5, 300 );

					if ( bValid ) {
						/*$('#dialog-form form').submit();
						*/
						$( '.ui-dialog' ).fadeTo('fast',0.2).find('.ui-button').attr('disabled','disabled');
						
						$.post(url+'ajax/sendtofriend.html',$('#dialog-form form').serialize(),function(res){
							if(res.sent == true)
							{
								subscribe_sent =true;
								$( '#dialog-form' ).dialog( "destroy" );
							}
							else
							{
								$( '.ui-dialog' ).fadeTo('fast',1).find('.ui-button,input').attr('disabled','');
							}
							alert(res.msg);
						});
						
						
					}
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			},
			open: function() {
				$( '.ui-dialog' ).fadeTo('fast',1).find('.ui-button,input').attr('disabled','');
			}
		});
		$( "a.sendtofriend" ).click(function()
		{
			if ( subscribe_sent == false )
			{
				$( "#dialog-form" ).dialog( "open" );	
			}
			else
			{
				alert('Please reload web page [ F5 ]');
			}
			
			return false;
		});
		

});
//************ GOOGLE MAP **************//

var marker;
function loadMap( elm , lat , lng , zoom ,popupInfo) {
		if (GBrowserIsCompatible())
		{
			
			var map = new GMap2(document.getElementById(elm));
			map.setCenter(new GLatLng(lat, lng), zoom);
			map.disableDoubleClickZoom();
			//map.addControl(new GOverviewMapControl());
			map.addControl(new GLargeMapControl3D ());
			map.addControl(new GMapTypeControl());
			
			//map.addControl(new GSmallZoomControl3D());
			
			//map.addControl(new GNavLabelControl());
			
			var icon_pin = new GIcon();
			icon_pin.image = urlStyle + 'images/marker.gif';
			icon_pin.shadow = urlStyle + 'images/marker_shadow.png';
			icon_pin.iconSize = new GSize(32, 32);
			icon_pin.shadowSize = new GSize(52, 35);
			icon_pin.iconAnchor = new GPoint(15,35);
			icon_pin.infoWindowAnchor = new GPoint(35,0);
			
			markerOptions = {draggable: false, icon: icon_pin};
			marker = new GMarker(map.getCenter(), markerOptions);
			map.checkResize();
			var balloonInfo = "<h4>"+popupInfo+"<\/h4>";
			
			map.addOverlay(marker);
			marker.openInfoWindowHtml(balloonInfo);
			GEvent.addListener(marker, "click", function(){
				marker.openInfoWindow(balloonInfo);
				
			});
			
			
			MapLoaded=true;
		 } //_if
} //__end func


function googleTranslateElementInit() {
		new google.translate.TranslateElement({
		  pageLanguage: 'en'
		}, 'google_translate_element');
	}
