// HANDLE PREMISES TOP MOUSE-OVER IMAGE --------------------------------------

addOnLoad('init_start_premsiesTop()');


function init_start_premsiesTop() {
	if( document.getElementById('top_premises') && document.getElementById('start_page') ) {
		var top_premises = document.getElementById('top_premises');
		var top_premises_dds = top_premises.getElementsByTagName('DD');
	
		for( i = 0 ; i < top_premises_dds.length ; ++i) {
			if( top_premises_dds[i].className == 'img' && top_premises_dds[i].getElementsByTagName('IMG')[1] ) {
				top_premises_dds[i].style.cursor = 'pointer';
				top_premises_dds[i].onclick = start_premsiesTop_goURL;
				top_premises_dds[i].onmouseover = start_premsiesTop_showImg;
				top_premises_dds[i].onmouseout = start_premsiesTop_hideImg;
			}
		}
	}
}

var start_premsiesTop_imgFrame;
var start_premsiesTop_img;

function start_premsiesTop_showImg() {
	var wrapper = document.getElementById('wrapper');
	var img = this.parentNode.getElementsByTagName('IMG')[1];
			if( !document.getElementById('premisesTop_imgFrame') ) { 
				start_premsiesTop_imgFrame = document.createElement('DIV');
				start_premsiesTop_imgFrame.id = 'premisesTop_imgFrame';
				start_premsiesTop_imgFrame.style.top = '323px';
				start_premsiesTop_imgFrame.style.left = '100px';				
			} else {
				document.getElementById('premisesTop_imgFrame').innerHTML = '';
			}
			start_premsiesTop_img = document.createElement('IMG');
			start_premsiesTop_img.src = img.src;
	start_premsiesTop_imgFrame.appendChild(start_premsiesTop_img);
	wrapper.appendChild(start_premsiesTop_imgFrame);
}

function start_premsiesTop_hideImg() {
			start_premsiesTop_imgFrame = document.getElementById('premisesTop_imgFrame');
			start_premsiesTop_imgFrame.parentNode.removeChild(start_premsiesTop_imgFrame);
			start_premsiesTop_imgFrame = null;			
}

function start_premsiesTop_goURL() {
	var URL = this.parentNode.getElementsByTagName('A')[0].href;
	window.location.href = URL;
}

var start_bannerHTML = "";

function start_openCampaignMovie( movieSize ) {
	var docBody = document.getElementsByTagName('BODY')[0];
	var wrapper = document.getElementById('wrapper');	
	
	// Create overlay
	var popup_overlay = document.createElement('DIV');
			popup_overlay.id = 'popup_overlay_black';
			docBody.appendChild(popup_overlay);
			if( agent.indexOf('msie') != -1 || agent.indexOf('firefox') != -1 ) {
				start_resizeCampaignMovie();
				window.onresize = start_resizeCampaignMovie;						
			}	
			if( agent.indexOf('firefox') != -1 ) {
				popup_overlay.className = 'popup_overlay_black_ff_mac';
			}
	
	
	// Create main-container
	var start_campaignMovieWrapper = document.createElement('DIV');
			start_campaignMovieWrapper.id = 'start_campaignMovieWrapper';
			docBody.appendChild(start_campaignMovieWrapper);
			
	var start_campaignMovieContent = document.createElement('DIV');
			start_campaignMovieContent.id = 'start_campaignMovieContent';
			start_campaignMovieWrapper.appendChild(start_campaignMovieContent);			
	
	// Create close-button
	var popup_overlay_close = document.createElement('A');
			popup_overlay_close.id = 'popup_overlay_black_close';
			//popup_overlay_close.style.left = ( ( document.body.offsetWidth / 2 ) + 430 ) + 'px';
			popup_overlay_close.href = '#';
			popup_overlay_close.onclick = start_closeCampaignMovie;			
			start_campaignMovieContent.appendChild(popup_overlay_close);
	
	// Create flash-container
	var start_campaignMovie = document.createElement('DIV');
			start_campaignMovie.id = 'start_campaignMovie';
			start_campaignMovie.style.left = ( ( 960 / 2 ) - 334 ) + 'px';
			start_campaignMovieContent.appendChild(start_campaignMovie);
	
	// Hide drop-downs for IE6
	//if( agent.indexOf('msie 6.0') != -1 ) {
		var DDs = wrapper.getElementsByTagName('SELECT');
				for( i = 0 ; i < DDs.length ; ++i ) {
					DDs[i].style.visibility = 'hidden';
				}
	//}
	
	// Hide the banner and replace it with a JPG
	var campaign_start_large_swf = document.getElementById('campaign_start_large_swf');
			start_bannerHTML = campaign_start_large_swf.innerHTML;
			campaign_start_large_swf.innerHTML = '';	
			
	var banner_jpg = document.createElement('IMG');
			banner_jpg.src = '../swf/fh_banner.jpg';
			banner_jpg.style.width = '465px';
			banner_jpg.style.height = '275px';
	campaign_start_large_swf.appendChild(banner_jpg);
	
	
	// Movie sizes
	var movieSizes 		= new Array();
			movieSizes[1]	= 'fh_small.flv';
			movieSizes[2]	= 'fh_large.flv';
	
	if( movieSize == 1 ) {
		start_campaignMovie.style.top = '-20px';
	}
	
	// Variables to be sent to flash
	if( agent.indexOf('mac') != -1 ) {
		var platform = 'mac';
	} else if( agent.indexOf('win') != -1 ) {
		var platform = 'win';	
	} else {
		var platform = 'unknown';		
	}
	
	if( movieSize == 2 ) { var smallMovie = 'flv/' + movieSizes[1] } else { var smallMovie = '' }
	
	// Append the flash
	var so = new SWFObject("http://www.vasakronan.se/swf/videoplayer.swf?videourl=flv/" + movieSizes[movieSize] + "&platform=" + platform + "&smallMovie=" + smallMovie, "campaignMovie", "100%", "100%", "8", "#000000");
	//var so = new SWFObject("../swf/videoplayer.swf?videourl=flv/" + movieSizes[movieSize] + "&platform=" + platform, "campaignMovie", "100%", "100%", "8", "#000000");	
			if( agent.indexOf('win') != -1) {
				so.addParam("wmode", "transparent");
			}
			so.write("start_campaignMovie");
	
}

function start_onresize() {
	if (document.getElementById && document.getElementsByTagName && document.createTextNode) {
		start_resizeCampaignMovie();	
	}
}

function start_resizeCampaignMovie() {
	var popup_overlay = document.getElementById('popup_overlay_black');
	var winHeight = ( document.documentElement.clientHeight > document.body.offsetHeight ) ? document.documentElement.clientHeight : document.body.offsetHeight;
	var winWidth = ( document.documentElement.clientWidth > document.body.offsetWidth ) ? document.documentElement.clientWidth : document.body.offsetWidth;
	if( winHeight < 630 ) { winHeight = 630 }
	popup_overlay.style.height = winHeight + 'px';
	popup_overlay.style.width = winWidth + 'px';
}


function start_closeCampaignMovie() {
	var wrapper = document.getElementById('wrapper');
	var popup_overlay = document.getElementById('popup_overlay_black');
	var start_campaignMovieWrapper = document.getElementById('start_campaignMovieWrapper');
	popup_overlay.parentNode.removeChild(popup_overlay);
	start_campaignMovieWrapper.parentNode.removeChild(start_campaignMovieWrapper);
	
	var DDs = wrapper.getElementsByTagName('SELECT');
			for( i = 0 ; i < DDs.length ; ++i ) {
					DDs[i].style.visibility = 'visible';
				}	
	
	// Show the banner and remove the JPG
	var campaign_start_large_swf = document.getElementById('campaign_start_large_swf');
			campaign_start_large_swf.innerHTML = start_bannerHTML;

}

jQuery(document).ready(function() {

    // Undvik att bubblan laddas flera gånger
    var bubbleActive = false;

    var searchDropDown = jQuery('#search_premises fieldset select.searchValidationDistrict');
    // Nils
    //jQuery("#ctl00_AllWide_All_ctl28_min_area, #ctl00_AllWide_All_ctl28_max_area, ctl00_AllWide_All_ctl28_min_area").keydown(function(event) {
    jQuery(".post_search").keydown(function(event) {
        var ev = event;
        if (ev.keyCode == 13) {
            jQuery('#search_premises fieldset.button_container').click();
            if (!bubbleActive)
                jQuery('#search_premises fieldset.button_container input').click();
            return false;
        }

    });

    jQuery('#search_premises fieldset.button_container').click(function() {
        if (!searchDropDown.val()) {
            if (!bubbleActive) {
                jQuery('#search_premises fieldset select.searchValidationType').hide();

                var validation = jQuery('<div></div>').addClass('validation_bubble');

                validation.insertAfter(searchDropDown)
				.fadeIn('slow')
				.click(function() {
				    jQuery('#search_premises fieldset select.searchValidationType').show();
				    jQuery(this).fadeOut('slow', function() {
				        jQuery(this).remove();
				    });
				});

                bubbleActive = true;

            }

            return false;
        } bubbleActive = false;
    });

    jQuery('div.startConceptShower>select[name=startConceptSelect]').bind('change', changeStartConceptContent);
    var initConcept = jQuery('div.startConceptShower>div.active');
    if (initConcept.is('*') != false) {
        var initConceptId = initConcept.attr('id');
        initConceptId = initConceptId.split('_');
        initConceptId = initConceptId[1];
        jQuery('div.startConceptShower>select>option').removeAttr('selected');
        jQuery('div.startConceptShower>select[name=startConceptSelect]>option[value=' + initConceptId + ']').attr('selected', 'selected');
    }



});

/* start concept shower */

var changeStartConceptContent = function(e) {

	jQuery('div.startConceptInfo').removeClass('active');
	jQuery('div#conceptArea_'+jQuery(this).val()).addClass('active');
}