var currentShopId = 0;

jQuery().ready(function(){
	
	$('.fulllink').click(function() {
		window.location = $(this).find('a').attr('href');
	});

	jQuery('.accordion').accordion({ 
		header: '.toggler',
		active: '.selected',
		autoheight: false
	});
	var easing = "linear";
	var duration = 50;
	var callback = function(){if(jQuery.browser.msie){this.style.removeAttribute('filter');}};
	var callback_2 = function(){this.style.display="none";};
	$("#basketContent").animate({opacity:0},0);
	$("#basketButton").mouseenter(function(){
		var bc = document.getElementById("basketContent");
		bc.style.display ="block";
		$("#basketContent").animate({opacity:1}, {easing:easing,duration:duration,complete:callback});
	});
	$("#basket").mouseleave(function(){
		$("#basketContent").animate({opacity:0}, {easing:easing,duration:200,complete:callback_2});
	});
    jQuery('.carousel').jcarousel({
		scroll: 1
	});
	jQuery('.carousel_alt').jcarousel({
		scroll: 2
	});
	$(".slideshow").each(function(){
		slideshow(this);
	});
	$(".gallery").each(function(){
        $('a',this).lightBox();
    });
	
	$(".promovente").mouseenter( function() {
		$(".promovente").addClass("promovente_alt");						  
		$(".header").addClass("header_alt");
		$(".footer").addClass("footer_alt");
	});
	$(".promovente").mouseleave( function() {
		$(".promovente").removeClass("promovente_alt");						  
		$(".header").removeClass("header_alt");
		$(".footer").removeClass("footer_alt");
	});
	
	$('.network_item h3').click(function(){
		
		if($(this).parent().attr('shopId') != currentShopId){
		
			$('.network_item[shopId="'+currentShopId+'"] .desc').animate({height:'0px'}, 'slow', function(){
				$(this).css('display', 'none');
			});			
			
			currentShopId = $(this).parent().attr('shopId');			
			getFlashMovie("carteSwf").selectInFlash($(this).parent().attr('shopId'));			
			$(this).parent().find('.desc').css('display', 'block');	
			var heig = $(this).parent().find('.desc p').height() + $(this).parent().find('.desc small').height() + 10;					
			$(this).parent().find('.desc').animate({height:heig+'px'}, 'slow');				
		}
	});
	
	$('#LOXAM_Module h3').click(function(){
		getFlashMovie("carteSwf").selectInFlash($(this).parent().attr('shopId'));
	});
	
	$('#LOXAM_Module h3').mouseover(function(){
		getFlashMovie("carteSwf").overInFlash($(this).parent().attr('shopId'));
	});
	
	$('#LOXAM_Module h3').mouseout(function(){
		getFlashMovie("carteSwf").outInFlash($(this).parent().attr('shopId'));
	});
	
	$('.network_item h3').mouseover(function(){
		getFlashMovie("carteSwf").overInFlash($(this).parent().attr('shopId'));
	});
	
	$('.network_item h3').mouseout(function(){
		getFlashMovie("carteSwf").outInFlash($(this).parent().attr('shopId'));
	});
});

var typeSearch;
jQuery(function(){
    if (document.getElementById('typesearch')){
        $('#keywordsrental').autocomplete({
            serviceUrl:'/inc/autocomplete2.php',
            minChars:3, 
            delimiter: /(,|;)\s*/, // regex or character
            maxHeight:400,
            width:390,
            zIndex: 9999,
            deferRequestBy: 0, //miliseconds
            params: {
                type:'rental'
            }, //aditional parameters
            noCache: false, //default is false, set to true to disable caching
            // callback function:
            onSelect: function(){
                var regex = /\<a.+\href="(.+)".*>(.+)\<\/a\>/;
                matches = document.getElementById('keywordsrental').value.match(regex);
                if(matches && typeof(matches) != "undefined" && typeof(matches[1]) != "undefined" && typeof(matches[2]) != "undefined"){
                    window.location = matches[1];
                    document.getElementById('keywordsrental').value = matches[2];
                    return false;
                }
                document.getElementById('keywordsrental').value = document.getElementById('keywordsrental').value.toLowerCase();
                var s = document.getElementById('keywordsrental').value;
                if (s.match(/---.*/)){
                    document.getElementById('keywordsrental').value = '';
                }
                $('#keywordsrental').focus();
                $('#keywordsrental').parents('form.search').children('input[type=submit]').trigger('click');
            }
        });
        

        $('#keywordssale').autocomplete({
            serviceUrl:'/inc/autocomplete.php',
            minChars:3, 
            delimiter: /(,|;)\s*/, // regex or character
            maxHeight:400,
            width:390,
            zIndex: 9999,
            deferRequestBy: 0, //miliseconds
            params: {
                type:'sale'
            }, //aditional parameters
            noCache: false, //default is false, set to true to disable caching
            // callback function:
            onSelect: function(){
                document.getElementById('keywordssale').value = document.getElementById('keywordssale').value.toLowerCase();
                var s = document.getElementById('keywordssale').value;
                if (s.match(/---.*/)){
                    document.getElementById('keywordssale').value = '';
                }
                $('#keywordssale').focus();
            }
        });
        
    }
});
function showCategories(type){
	if(type=="sale"){
		var sales = document.getElementById("sale");
		sales.style.background = "#ffffff";
		document.getElementById("categoriesSale").style.display = "block";
		document.getElementById("main").style.height = "380px";
		var rental = document.getElementById("rental");
		rental.style.background = "none";
		document.getElementById("categoriesRental").style.display = "none";
	}else if (type=="rental"){
		var sales = document.getElementById("sale");
		sales.style.background = "none";
		document.getElementById("categoriesSale").style.display = "none";
		document.getElementById("main").style.height = "280px";
		var rental = document.getElementById("rental");
		rental.style.background = "#ffffff";
		document.getElementById("categoriesRental").style.display = "block";
	}
}

function showPricesLine(id){
	var tr = document.getElementById("pricesLine_"+id);
	tr.style.background = "#f4f4f4";
}
function hidePricesLine(id){
	var tr = document.getElementById("pricesLine_"+id);
	tr.style.background = "#ffffff";
}
function showCaracteristicsLine(id){
	var tr = document.getElementById("caracteristicsLine_"+id);
	tr.style.background = "#f4f4f4";
}
function hideCaracteristicsLine(id){
	var tr = document.getElementById("caracteristicsLine_"+id);
	tr.style.background = "#ffffff";
}

function slideshow(t){
	var active = 1;
	var total = $(".item", $(t)).size();
	var previous = 0;
	var time = 3000;
	var easing = "linear";
	var duration = 400;
	var callback = function(){if(jQuery.browser.msie){this.style.removeAttribute('filter');}};
	$(".item:gt(0)", $(t)).animate({opacity:0},0);
	function fadeIn(){
		$(".item:eq("+previous+")", $(t)).animate({opacity:0}, 400);
		$(".item:eq("+active+")", $(t)).animate({opacity:1},{easing:easing,duration:duration,complete:callback});
		setTimeout(fadeIn,time);
		previous = active;
		active++;
		if(active>total-1){
			active = 0;
		}
	}
	function startAnim() {
		setTimeout(fadeIn,time);
	}
	startAnim();
}

function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}

function selectShop(id){
	if(id != currentShopId){
		$('.network_item[shopId="'+currentShopId+'"] .desc').animate({height:'0px'}, 'slow', function(){
			$(this).css('display', 'none');
		});			
		
		currentShopId = id;			
		//getFlashMovie("carteSwf").selectInFlash(id);			
		$('.network_item[shopId="'+id+'"] .desc').css('display', 'block');	
		var heig = $('.network_item[shopId="'+id+'"] .desc p').height() + $('.network_item[shopId="'+id+'"] .desc small').height() + 10;					
		$('.network_item[shopId="'+id+'"] .desc').animate({height:heig+'px'}, 'slow');				
	}
}
/*var city = ["LOXAM Auderghem","LOXAM Bruxelles Nord","LOXAM Charleroi","LOXAM Drogenbos","LIEGE","LOXAM Namur","LOXAM Anvers","LOXAM Gand","LOXAM Courtrai","LOXAM Module"];

function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}
function sendToFlash(c) {
  
  getFlashMovie("carteSwf").sendTextToFlash(c);
 }

function highlight(mapName){
		document.getElementById(mapName).style.backgroundColor = "#efefef";
		
		for (var i=0; i<city.length; i++)
		{
		   if(mapName != city[i])
			{
				highlightOff(city[i]);
			}
		}
		
	}
	function highlightOff(mapName)
	{
		var d = document.getElementById(mapName);
		if(d){d.style.backgroundColor = "#ffffff";}
	}

	function highlightOffAll()
	{
		for(i=0;i<city.length;i++)
		{
			highlightOff(city[i]);
		}
	}
function boxOffHover(box) {
box.style.background='#cccccc';
}

function boxOnHover(box) {
box.style.background='#f3f3f3';
}*/

