
jQuery(document).ready(function(){


function hideBlocks(anim){
		$("#shops").addClass("hideThis");	
		$("#shopCard").addClass("hideThis");
		$(".infoC1").addClass("hideThis");
		//hauteur du box bleu:
		//$("#container").animate({ height: 159 }, "slow");
		$("#container").css({"height":159});
}
function showBlocks(){
		$("#shops").removeClass("hideThis");	
		$("#shops").addClass("showThis");
		$("#shopCard").removeClass("hideThis");	
		$("#shopCard").addClass("showThis");
		$(".infoC1").addClass("showThis");
		//hauteur du box bleu:
		//$("#container").animate({ height: 825 }, "slow");
		$("#container").css({"height":825});
}
function showBlocks12(){
		$("#shops").removeClass("hideThis");		
		$(".infoC1").addClass("showThis");
//		$("#shopCard").removeClass("hideThis");	
		//hauteur du box bleu:
		//$("#container").animate({ height: 490 }, "slow");
		$("#container").css({"height":490});
}
//HIDE ALL AT BEGINNING OF PROCESSUS
$("#container").css({"height":159});
$("#shops").addClass("hideThis");	
$("#shopCard").addClass("hideThis");
$(".infoC1").addClass("hideThis");

		
//Si on clique sur city, afficher les bloques
$("#worldzone").click(function(event, a, b) {
		hideBlocks();
} );
$("#country").click(function(event, a, b) {
		hideBlocks();
} );
$("#city").click(function(event, a, b) {
		hideBlocks();
		showBlocks12();
		$("#contentForm").addClass("hideThis");
} );

/******************************************************
ADRESS ACCORDION
*******************************************************/
$("#add1 div").hide();
$("#add1").click(function(event, a, b) {
		$("#add1 div").toggle();
		$("#add4 div").hide();
		$("#add2 div").hide();
		$("#add3 div").hide();
		$("#add5 div").hide();
} );
$("#add2 div").hide();
$("#add2").click(function(event, a, b) {
		$("#add2 div").toggle();
		$("#add1 div").hide();
		$("#add4 div").hide();
		$("#add3 div").hide();
		$("#add5 div").hide();
} );
$("#add3 div").hide();
$("#add3").click(function(event, a, b) {
		$("#add3 div").toggle();
		$("#add1 div").hide();
		$("#add2 div").hide();
		$("#add4 div").hide();
		$("#add5 div").hide();
} );
$("#add4 div").hide();
$("#add4").click(function(event, a, b) {
		$("#add4 div").toggle();
		$("#add1 div").hide();
		$("#add2 div").hide();
		$("#add3 div").hide();
		$("#add5 div").hide();
} );
$("#add5 div").hide();
$("#add5").click(function(event, a, b) {
		$("#add5 div").toggle();
		$("#add1 div").hide();
		$("#add2 div").hide();
		$("#add3 div").hide();
		$("#add4 div").hide();
} );

/******************************************************
FILTER flow

Worldzone > country > city

*******************************************************/
    $.fn.selectChain = function (options) {
        var defaults = {
            key: "id",
            value: "label"
        };
        
        var settings = $.extend({}, defaults, options);
        
        if (!(settings.target instanceof $)) settings.target = $(settings.target);
        
        return this.each(function () {
            var $$ = $(this);
            
            $$.change(function () {
			
                var data = null;
                if (typeof settings.data == 'string') {
                    data = settings.data + '&' + this.name + '=' + $$.val();
                } else if (typeof settings.data == 'object') {
                    data = settings.data;
                    data[this.name] = $$.val();
                }
                
                settings.target.empty();
                
                $.ajax({
                    url: settings.url,
                    data: data,
                    type: (settings.type || 'get'),
                    dataType: 'json',
                    success: function (j) {
                        var options = [], i = 0, o = null;
                        
                        for (i = 0; i < j.length; i++) {
                            // required to get around IE bug (http://support.microsoft.com/?scid=kb%3Ben-us%3B276228)
                            o = document.createElement("OPTION");
                            o.value = typeof j[i] == 'object' ? j[i][settings.key] : j[i];
                            o.text = typeof j[i] == 'object' ? j[i][settings.value] : j[i];
                            settings.target.get(0).options[i] = o;
                        }

						// hand control back to browser for a moment
						setTimeout(function () {
					    settings.target
                                //.find('option:first')
                                //.attr('selected', 'selected')
                                ///.parent('select')
                                .trigger('change');
						}, 0);
						
                    },
                    error: function (msg,xhr, desc, er) {
                        // add whatever debug you want here.
						//alert("sorry, an error occurred in main script, try later. ");
						jAlert('sorry, an error occurred in main script, try later.', 'Alert Dialog');

                    }
                });
                
            });
        });
    };
    
	
/******************************************************
GMAP <> list of shops

*******************************************************/
$.fn.selectShop = function (options) {
        var defaults = {
            key: "id",
            value: "label"
        };
        
        var settings = $.extend({}, defaults, options);

var $$ = $(this);

     $$.change(function () {
     
     var data = null;
     var postData = settings.data.serialize()+"&country="+$('#country').val();
     
	 $.ajax({ 	
		type: 'post',
		datatype: 'html',
		url: 'includes/viewArrayCard.php',
		data: postData,
		success: function (data) { //ouvrir
			//alert(data);
             $('#content_file_ajax_shop').hide();
             $('#content_file_ajax_shop').html('<img src="templates/prototype/data/loading.gif" />');
             $('#content_file_ajax_shop').empty().html('<img src="templates/prototype/data/loading.gif" />');
             $('#content_file_ajax_shop').html(data);
             $('#content_file_ajax_shop').show();            
	    },
		error: function (msg,xhr, desc, er) {
			// add whatever debug you want here.
			//alert("sorry, an error occurred from shop, try later. ");
			jAlert('sorry, an error occurred in shop script, try later.', 'Alert Dialog');
		}
	 	});
	$.ajax({ 	
		type: 'post',
		datatype: 'html',
		url: 'includes/viewArrayRow.php',
		data: postData,
		success: function (data) { //ouvrir
			//alert(data);
             $('#content_file_ajax').hide();
             $('#content_file_ajax').html('<img src="templates/prototype/data/loading.gif" />');
             $('#content_file_ajax').empty().html('<img src="templates/prototype/data/loading.gif" />');
             $('#content_file_ajax').html(data);
             $('#content_file_ajax').show();           
	    },
		error: function (msg,xhr, desc, er) {
			// add whatever debug you want here.
			//alert("sorry, an error occurred from list of shops, try later.");
			jAlert('sorry, an error occurred in shops script, try later.', 'Alert Dialog');
		}
	 	});

	 });
};



});
