
var schmapplet = {view: 'places',viewid:'places', scrollOffset: 0,
                  IEquirks: document.documentElement.style.filter !== undefined,
                  placesById: {}}; 
var b_version=navigator .appVersion;
var downhref=''
var counter=9;
var maxd=9;
var selector;
connect(window, 'onload', aboutGuideInit);
function aboutGuideInit(){	
if(b_version.search(/MSIE 6/i)   !=   -1) {
        var imgs = document.getElementsByTagName('img');
        logDebug('DAMN IE!!!  I have to replace ' + imgs.length + ' images');
        for(var i = 0; i < imgs.length; i++) {
            var img = imgs[i];
            if(img.src.match(/\.png$/))
                swapDOM(img, PNG({src: img.src, alt: img.alt,
                                  width: 39, height: 33}));
        }
    }
  	selector = new GuideSelector('picker-country', 'picker-city');
     if(BrowserDetect.OS == 'Mac') {
	  $('wn').innerHTML = '199';
	  $('en').innerHTML = '95';
	  $('an').innerHTML = '94';
	   $('world').innerHTML = '(762MB)';
	   $('europe').innerHTML = '(95MB)';
	   $('america').innerHTML = '(95MB)';
	   $('link1').href ="http://www.schmap.com/installers_mac/World/Schmap_Player.dmg.gz";
       $('link2').href ="http://www.schmap.com/installers_mac/Europe/Schmap_Player.dmg.gz";
	   $('link3').href ="http://www.schmap.com/installers_mac/NorthAmerica/Schmap_Player.dmg.gz";
	   changeWin();	
	   
    } else {
	      downhref='/schmap_setup.exe';
       changeWin();
    }
    //selector.preselect_by_name = curCityName;
 	connect('downloadbutton', 'onmouseover', styleChanged);
	connect('downloadbutton', 'onmouseout', styleOut);
	connect('downloadbutton', 'onclick', downloadbuttonlink);
  	//selector.ready(); 
//	hideElement('info-panel-outer');
	callLater(0.2, onChangeCityName);

}
function GuideSelector(country_sel, city_sel) {
    this.country_select = $(country_sel);
    this.city_select = $(city_sel);
    this.preselect_by_name = null;
    this.preselect = 2001;
    this.by_id = {};
    this.by_country = {};
	for(var i = 0; i < data.length; i++){
	    var countryName = data[i][0];
		this.country_select.options[i] =
            new Option(countryName, countryName);
	}
	connect(this.country_select, 'onchange', this, 'syncSelects');
    connect(this.city_select, 'onchange', onChangeCityName);
	this.country_select.selectedIndex = defualtIndex;
	this.syncSelects();
}


GuideSelector.prototype.syncSelects = function() {	
    var index = this.country_select.selectedIndex;    
    var country = this.country_select.options[index].value;
	this.countryname=country;
    var selected = null;
    var lowest_id = 99999;
    var lowest_index = 0;
    this.city_select.options.length = 0;
	var cityList = data[index][2];
    for(var c = 0; c < cityList.length; c++) {
        var guide = cityList[c];
        var option = new Option(guide[0], guide[1]);
		option.sizemb = guide[2];
        this.city_select.options[this.city_select.options.length] = option;
  
    }
	this.city_select.selectedIndex = data[index][1];
    callLater(0.2, onChangeCityName);
	
}
function onChangeCityName() {
	$('curcity').innerHTML = selector.city_select.options[selector.city_select.selectedIndex].text;
    if(BrowserDetect.OS == 'Mac') {
         changeWin(); 
    } else { 
 		changeWin();
    }	
	// var citynamefrom=selector.city_select.options[selector.city_select.selectedIndex].text.replace(' ','');
	// if(selector.countryname=='United States'){
		// if(citynamefrom=='Birmingham'){
				// citynamefrom ='BirminghamUS'
		// }
	// }

       
   connect($('downloadbutton'),'onclick',downloadbuttonlink);

}
function styleChanged() {
 this.style.cursor = 'pointer';
 this.style.textDecoration = 'underline';
}
function styleOut() {
	this.style.cursor = '';
    this.style.textDecoration = 'none';
}

function downloadbuttonlink(){
	var currentTxt = selector.city_select.options[selector.city_select.selectedIndex].value;
	currentTxt = 'http://www.schmap.com/'+currentTxt;
	logDebug(currentTxt);
	window.location.href = currentTxt+downhref;

}
 function PNG(attrs) {
    var src = attrs.src;
    if(schmapplet.IEquirks)
        attrs.src = '/images/pageicons/spacer.png';
    img = MochiKit.DOM.IMG(attrs);
    if(schmapplet.IEquirks) {
        setElementDimensions(img, {h: attrs.height, w: attrs.width});
        img.style.filter = "progid:DXImageTransform.Microsoft." +
            "AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
    }
    return img;
}

function changeMac() {
 
      if(typeof(selector.city_select.selectedIndex) == 'undefined'){
           var  citycode = '2001';
      } else {
        var citycode = selector.city_select.options[selector.city_select.selectedIndex].value;
       }
      $('mbSize').innerHTML = '('+guidesInfoForMac[citycode.toString()].s+'MB)' ;
}

function changeWin() {
       if(typeof(selector.city_select.selectedIndex) == 'undefined'){
           var  sizemb = '3';
      } else {
        var sizemb = selector.city_select.options[selector.city_select.selectedIndex].sizemb;
       }
       $('mbSize').innerHTML = '('+sizemb+'MB)' ;
 }