
$(document).ready(function() {
	$(".box").addClass('ui-corner-all');
	$(".ui-widget-header").addClass("ui-corner-top");
	$(".ui-widget-content").addClass("ui-corner-bottom");
	$(".img_sidebar img").addClass('ui-corner-all');

	$('#all_stores').masonry({
    singleMode: true, 
    itemSelector: '.box' 
});
	$("#shopSearch").autocomplete("/content/shops/shop_ajax.php", {
		width: 235,
		selectFirst: false
	});
	
    $('#shopSearch').keyup(function(e) {
		var shop_url = "";
		var country = "";
		var str = "";
		
		if((e.keyCode == 13) ) {
      		
			var str = $(this).val();
			var country = $(this).attr('lang');
			var shop_url = "/search/"+country+""+str;
			
			//console.log("i con.js: "+shop_url+"\n"+"str: "+str);
			window.parent.location=shop_url;
			
      }
      });
	  
    //$('.social_tools li ').tipsy({gravity: 'n'}); // nw | n | ne | w | e | sw | s | se
    $('#twitter').tipsy({gravity: 'se'});
    $('#blog').tipsy({gravity: 'se'});
    $('#youtube').tipsy({gravity: 'se'});
    $('#facebook').tipsy({gravity: 'se'});

    
	$("#save_email").click(function(){
			var email = $("#email_field").val();
			var shop_id = $("#shop_id").val();
			var shop_url = $("#shop_url").val();
			//$('#shop_grid_container').html("");
			//$('#success_saved').fadeOut("fast");
			$('#email_loader').fadeIn("fast");
			$.manageAjax.add('emailAjax', { 
				  url: '/content/shops/email_saver.php',
				 data: "email="+email+"&shop_id="+shop_id,
				  success: function(data) { 
						$('#email_loader').fadeOut("fast");
						
						
						$('#success_saved').fadeIn("slow");
						window.parent.location=shop_url;
						
				  
				}
			});
		});
	
	
	$(function(){ $('#portfolio').equalHeights(); });
	
	/*
	 * ADMIN
	 */
	
	$('#lanuage_admin').change(function()
	{
		 $.ajax({
			   type: "POST",
			   url: "/content/admin/setDBLanguage.php",
			   data: "country="+ $(this).val(),
			   success: function(data){
			 if(data == "1")
				{
					//$("#container").html("<b>SESSION Setup Successfully!</b>");
					alert("OK");
				} else {
					//$("#container").html("<b>Something Broke! HELP!</b>");
					alert("NOT OK :(");
				}
			   }
			 });

		 /*
		$.ajax("/content/admin/setDBLanguage.php", {country: $(this).val()}, function(data){
			
			if(data == "1")
			{
				//$("#container").html("<b>SESSION Setup Successfully!</b>");
				alert("OK");
			} else {
				//$("#container").html("<b>Something Broke! HELP!</b>");
				alert("NOT OK :(");
			}
		});*/

	});
	
	$("#admin_node_tabs").tabs();
	
	
	$('.toplist-check').change(function(){
		var checked;
		if ($(this).is(":checked"))
			checked = 1;
		else
			checked = 0;
		console.log("ID: "+$(this).attr('id'));
		$.manageAjax.add('makeTopshop', { 
		  url: '/content/shops/shop_ajax.php',
		  data: "makeTop&shop_id="+$(this).attr('id')+"&value=" + checked,
		  success: function(data) { 
		 	
				}
		  });
		});
	
	
	/*
	 * SHOPGRID and SHOPS
	 */
	
	$("ul#portfolio li").hover(function() {
	    $(this).animate({ backgroundColor: "#FAFAFA" }, "slow");
	},function() {
	    $(this).animate({ backgroundColor: "#FFF" }, "fast");
	});
	
	
	
	/*
	 * Frontpage filtering
	 */
	
	$("input#search").ezpz_hint();
	$("input#shopSearch").ezpz_hint();
	
	$('#search_field').focus(function() {  
		//$('#contribute_steps').localScroll();
		//console.log("focus");
		$.scrollTo("#idea_img");
		//$('#search_field').focus();
	
	});
	$("#do_search").click(function(){
		$('#shop_grid_container').html("");
	$('#shop_loader').fadeIn("fast");
	
	var str = document.getElementById('shopSearch').value
	$.manageAjax.add('shopAjax', { 
		  url: '/content/shops/shop_ajax.php',
		  data: "search="+str,
		  success: function(data) { 
				$('#shop_loader').fadeOut("fast",function(){
				$('#shop_grid_container').html(data); 
				//$("#portfolio li").equalHeight();
				$(function(){ $('#portfolio').equalHeights(); });
		  });
		}
	});
	
	});

	
	
	$(function() {
		$("#selectable").selectable({
			stop: function(){
			// window.parent.location="#category-container";
				var result = $("#select-result").empty();
				$(".ui-selected", this).each(function(){
					var index = $(this).attr('id');
					$('#shop_loader').fadeIn("slow");
					$('#shop_grid_container').html("");
					
					$.manageAjax.add('shopAjax', { 
						  url: '/content/shops/shop_ajax.php',
						  data: "c="+index,
						  success: function(data) { 
								$('#shop_loader').fadeOut("slow",function(){
								$('#shop_grid_container').html(data); 
								//$("#portfolio li").equalHeight();
								
								$(function(){ $('#portfolio').equalHeights(); });
						  });
						}
					});
						/*
						 *
						 *if (index == 0) {
							$('ul#portfolio li.ui-helper-hidden-accessible').removeClass('ui-helper-hidden-accessible');
						}
						else {
							$("#portfolio li").each(function(){
							
								if ($(this).attr("id") == index) {
									$(this).removeClass("ui-helper-hidden-accessible");
									
								}
								else {
									$(this).addClass("ui-helper-hidden-accessible");
								}
							});
						}
						*/
					
				});
				return false;
			}
		});
		$("#selectable li:first").addClass("ui-state-active");

	});
	$(function(){
		//all hover and click logic for buttons
		$(".fg-button:not(.ui-state-disabled)")
		.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
				
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
		.mousedown(function(){
				$(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
				if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
				else { $(this).addClass("ui-state-active"); }	
		})
		.mouseup(function(){
			if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
				$(this).removeClass("ui-state-active");
			}
		});
	});
	
	
	
		
		
		
			
			
		

	
});



