jQuery.noConflict();

(function($) {


		showResponse = function(responseText, statusText)  { 
		    alert(responseText);
		}
		
		RedirectToResults = function(responseText, statusText)  { 
		     window.location = BASE_URL + "search/results/" + responseText;
		}
		
		front_search_progress = function() {		
			$('#front-search-engine-progress').css("display","block");
			$('#front-search-engine-form-stats').css("display","none");
			$('#front-search-engine-form-terms').css("display","none");		
			
		}
		
		
		postavi_autocomplete_polja = function() {
			
			// CITY
			 $("#city").autocomplete(BASE_URL + 'ajax/autocompleteCity', {
		        multiple: false,
		        selectFirst: false
		    });
		    
		}
		
		
     	activateFrontSearchForm = function(objS){
			searchFormFields(objS.options[objS.selectedIndex].value);
			//alert(objS.options[objS.selectedIndex].value);
		}
		
		
		searchFormFields = function(id) {

			switch (id) {	
				
				case '1':
					$('#front-search-engine-progress').css("display","none");
					$('#front-search-engine-form-stats').css("display","none");
					$('#front-search-engine-form-terms').css("display","block");
				break;	
				
				case '2':
					$('#front-search-engine-progress').css("display","none");
					$('#front-search-engine-form-stats').css("display","none");
					$('#front-search-engine-form-terms').css("display","block");
				break;	
				
				case '3':
					$('#front-search-engine-progress').css("display","none");
					$('#front-search-engine-form-stats').css("display","none");
					$('#front-search-engine-form-terms').css("display","block");
				break;	
				
				case '4':
					$('#front-search-engine-progress').css("display","none");
					$('#front-search-engine-form-stats').css("display","none");
					$('#front-search-engine-form-terms').css("display","block");
				break;	
				
				case '5':
					$('#front-search-engine-progress').css("display","none");
					$('#front-search-engine-form-stats').css("display","none");
					$('#front-search-engine-form-terms').css("display","block");
				break;		
				
				
				default:
					$('#front-search-engine-progress').css("display","none");
					$('#front-search-engine-form-stats').css("display","block");
					$('#front-search-engine-form-terms').css("display","none");
				break;						
			
			}
			
		}	
		
		
		setupSupplierNewsList = function(){
			$('ul.suppliers-news-list li').mouseover(function() {
				
		        var news_id_full = $(this).attr("id");
				var news_id = news_id_full.split("-");
				//news_id[3]
				
				
				var current_news_detail_full = $("ul.suppliers-news-details li:visible").attr("id");
				var current_news_detail = current_news_detail_full.split("-");
				//current_news_detail[4]
				

				
				if (current_news_detail[4] != news_id[3]) {
					//$("#" + current_news_detail_full).fadeOut('fast');
					//$("#supplier-news-detail-id-" + news_id[3]).fadeIn('fast');			
					$("#" + current_news_detail_full).css("display", "none");
					$("#supplier-news-detail-id-" + news_id[3]).css("display", "block");
					
					$("ul.suppliers-news-list li").each( function() {
						 var tmp_id = $(this).attr("id");
						 $("#" + tmp_id).css("background-color", "#ffffff");
					});
					
					$("#supplier-news-id-" + news_id[3]).css("background-color", "#efefef");
				}

				
		
			});			
		}		
		
		
		


			document.write("<style type='text/css'>.hidden{display:none;}<\/style>");
			
			$(document).ready(function(){


				$("a[rel^='prettyPhoto']").prettyPhoto({
					animationSpeed: 'normal', /* fast/slow/normal */
					padding: 40, /* padding for each side of the picture */
					opacity: 0.55, /* Value betwee 0 and 1 */
					showTitle: true, /* true/false */
					allowresize: true, /* true/false */
					counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
					theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
				});
				
				
				$('.spotlight-content').cycle({
				    fx:      'turnDown',
				    delay:   0,
				    timeout: 8000,
				    cleartypeNoBg: true
				});
				
				$('.features-suppliers-content').cycle({ 
				    fx:     'scrollUp', 
				    timeout: 6000, 
				    delay:  -2000 
				});
				
				$(".latest-supp-content").jCarouselLite({
					vertical: true,
					hoverPause:true,
					visible: 6,
					auto:2000,
					speed:2000
				});
				
				// events
				$('.upcoming-events-content-list').css("display","block");
 				$("ul#ticker-events").liScroll({travelocity: 0.05}); 
 				


				
				
	        	// POCETAK AJAXIRANJA FORME
				var options = { 
				 // target:     	'.form_error', 
				    beforeSubmit:	  front_search_progress,
				    success:  		  RedirectToResults   
				};         	         
	            $('#front_search_engine_form').ajaxForm(options);
				/////// KRAJ AJAXIRANJA FORME
				
				
				// Autocomplete priprema
				postavi_autocomplete_polja();
				
	
				//aktiviraj Hotels polja
				searchFormFields(0);
				
				//suppliers news list
				setupSupplierNewsList();
			
				
				//form submit false trigger
				$("#front_search_engine_form").submit(function() { return false; });
					
			
				$('#username').coolinput({
					blurClass: 'form-text-hint',
				    hint: 'username'
				});
				
				$('#password').coolinput({
					blurClass: 'form-text-hint',
				    hint: 'password'
				});

				

			});

})(jQuery);



