$('.more-info').hide();
$('.shoe .title').hide();

$('#movie').flash(
    { src: 'images/celtics.swf',
      width: 650,
	  wmode: "opaque",
      height: 230 }
);
$('#movie .description').hide();

$('#searchloc').bind('keypress',function(e) {
	 var code = (e.keyCode ? e.keyCode : e.which);
	 if(code == 13) { //Enter keycode
	  	search_map();
	 }
});

$('#mapsearch').click( function() {
	search_map();
});

$('#sitemap').click( function() {
	toggleMenu();
});

$('.shoe-item').each(function() {
	var child = $(this).contents().find(".more-info");
	var title = $(this).contents().find(".title");

	jQuery(child).dialog({
	    autoOpen: false,
	    modal : true,
	    width: 620,
	    minHeight: 480,
	    title : title.html()
	});

	$(this).click(function() {
		jQuery(child).dialog('open');
	});
});



$('.popup').each(function() {
	var child = $(this).children(".longText");
	var title = $(this).children(".title");
    var flash = $('.flash');
	
	//must be a child of a child
	if (child.length == 0) {
		var child = $(this).contents().find(".longText");
		var title = $(this).contents().find(".title");
	}
	jQuery(child).dialog({
	    autoOpen: false,
	    modal : true,
	    width: 400,
	    maxHeight: 700,
	    title : title.html(),
        close : function() {
            flash.css('visibility', 'visible');
        }
	});	

	$(this).click(function() {
        flash.css('visibility', 'hidden');
		jQuery(child).dialog('open');
	});
});

function search_map() {
	$('.store-search .error').hide();
	$('#map_empty').hide();
	$('#map_canvas').show();
	search_markers();
};

var intervalId = null; 

function toggleMenu() {
  clearInterval(intervalId);
  menuObj = document.getElementById("schuifmenumasker");
  if (document.getElementById("schuifmenu").getAttribute("menustate") == "closed") {
    slideDirection = "up";
    menuState = "open";
    menuHeight = document.getElementById("schuifmenu").scrollHeight;
  } else {
    slideDirection = "down";
    menuState = "closed";
    menuHeight = 0;
  }
  document.getElementById("schuifmenu").setAttribute("menustate", menuState);
  var slideSpeed = !document.all ? 11 : 5
  startSlide(menuObj, slideSpeed, menuHeight, slideDirection);
}



function startSlide(obj, slideStep, slideHeight, slideDirection, slideSpeed) {
  var slideSpeed = !slideSpeed ? 15 : slideSpeed;
  var slideDirection = !slideDirection ? "down" : slideDirection;
  if (intervalId) {
    clearInterval(intervalId);
  }
  //status = "interval gestart " + slideStep + ", " + slideHeight + ", scrollHeight:" + obj.scrollHeight + ", height:" + obj.clientHeight;
  intervalId = setInterval(function() {
    switch(slideDirection){
      case "down": 
        newHeight = obj.clientHeight + slideStep;
        if (newHeight >= slideHeight) {
          newHeight = slideHeight
        } 
        break;
      case "up": 
        newHeight = obj.clientHeight - slideStep;
        if (newHeight <= slideHeight) {
          newHeight = slideHeight;
        }
        break;
    }
    obj.style.height = newHeight + "px";
    if (slideHeight == newHeight) {
      //status = "Clear interval";
      clearInterval(intervalId);
    }
  }, slideSpeed);
}
