jQuery.noConflict();

var PopupLasik = 
{
	show : function(url, displayWidth, displayHeight)
	{
		Lightview.show({ href: url, rel: 'iframe', title: '', options: {topclose: true, width : displayWidth, height : displayHeight, autosize: true} });		
	}	
}

// IE PNG Fix

if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) &&
	document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
{
	document.styleSheets[0].addRule('img', 'behavior: url(/lasikmd_site/js/iepngfix.htc)');
}

 
// Menu dropdown for IE6
sfHover = function() {
	if ($("menu_ul"))
	{
		var sfEls = $("menu_ul").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


jQuery(document).ready(function() { 
		if (document.all && (/MSIE (8)/.test(navigator.userAgent) || /MSIE (7)/.test(navigator.userAgent)))
		{
			jQuery('#menu_ul').superfish({ 
				delay:       200,                            // one second delay on mouseout 
				animation:   {height:'show'},  // fade-in and slide-down animation 
				speed:       'normal',                          // faster animation speed 
				autoArrows:  false,                           // disable generation of arrow mark-up 
				disableHI:     false,
				pathLevels:    1,
				dropShadows: false                            // disable drop shadows 
			});
		}
		else
		{
			jQuery('#menu_ul').superfish({ 
				delay:       200,                            // one second delay on mouseout 
				animation:   {opacity:'show', height:'show'},  // fade-in and slide-down animation 
				speed:       'normal',                          // faster animation speed 
				autoArrows:  false,                           // disable generation of arrow mark-up 
				disableHI:     false,
				pathLevels:    1,
				dropShadows: false                            // disable drop shadows 
			});
		}
    }); 


// put social footer to bottom
Event.observe(window, 'load', function(){socialFooterBottom();});

function socialFooterBottom()
{
	if ($('content_left') && !$('careers_form_step1'))
	{
		var leftheight = $('content_left').getHeight();
		var rightheight = $('content_right').getHeight();
		var rightheightdyn = $('content_right_dynamic').getHeight();
		if(rightheight < leftheight)
		{
			$('content_right_dynamic').style.height = leftheight - 195 + 'px';
		}
	}
}



// General Effects

function AppearEffect(element){
	new Effect.toggle(element, 'Appear', {duration:0.5});
}

function BlindEffect(element){
	new Effect.toggle(element,'Blind', {duration:1});
}

function showChild(element) {
	new Effect.toggle(element + '_ul', 'Appear', {duration:0.3});
	var linkpath = $(element + '_img').src;
	if ($(element + '_img').name == "off")
	{
		var newlinkpath = linkpath.replace('icon_leftmenu','icon_selected_leftmenu');
		$(element + '_img').name = "on";
	}
	else
	{
		var newlinkpath = linkpath.replace('icon_selected_leftmenu','icon_leftmenu');
		$(element + '_img').name = "off";
	}
	$(element + '_img').src = newlinkpath;
}


// Change text sizes

function resizeText(multiplier) {
	$('content_right_dynamic').style.fontSize = parseFloat($('content_right_dynamic').style.fontSize) + (multiplier * 0.2) + "em";
	$('content_right_dynamic').style.lineHeight = parseFloat($('content_right_dynamic').style.lineHeight) + (multiplier * 0.2) + "em";
}


// Popup Change City

/*
function changeCity(url) {
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			$('popup_changecity').innerHTML = transport.responseText;
			Lightview.show({ href: '#popup_changecity', rel: 'inline', title: '', options: {topclose: true, autosize: true} });
		}
	});
}
*/

function changeCity(url) {
	Lightview.show({ href: '#popup_changecity', rel: 'inline', title: '', options: {topclose: true, autosize: true} });
}

Event.observe(window, 'load', function(){
	if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent))
	{
		var ie6 = "1";
	}
	
	if ($('block_nextstep_container'))
	{
		Event.observe(window, 'scroll', function(){
			
			var containerCoord = $('block_nextstep_container').cumulativeOffset();
			var coord = $('block_nextstep').cumulativeOffset();
			var leftcoord = $('block_nextstep_container').viewportOffset();
			var maxbottom = Position.getWindowSize().height - 352;
			if (ie6 != "1")
			{
				if ($('block_nextstep').style.position == "fixed")
				{
					if (posTop() < containerCoord[1])
					{
						
						$('block_nextstep').style.position = "static";
						$('block_nextstep').style.top = "";
					}
					else if (posTop() >= maxbottom)
					{
						$('block_nextstep').style.top = "-40px";
					}
					else
					{
						$('block_nextstep').style.top = "10px";
					}
				}
				else
				{
					if (posTop() >= coord[1])
					{
						$('block_nextstep').style.position = "fixed";
						$('block_nextstep').style.top = "10px";
						$('block_nextstep').style.left = leftcoord[0] + "px";
					}
				}
			}
			else //is IE 6
			{
				if ($('block_nextstep').style.position == "absolute")
				{
					if (posTop() < containerCoord[1])
					{
						
						$('block_nextstep').style.position = "static";
						$('block_nextstep').style.top = "";
					}
					else if (posTop() >= maxbottom)
					{
						$('block_nextstep').style.top = document.documentElement.scrollTop - 40 + "px";
					}
					else
					{
						$('block_nextstep').style.top = document.documentElement.scrollTop + 10 + "px";
					}
				}
				else
				{
					if (posTop() >= containerCoord[1])
					{
						$('block_nextstep').style.position = "absolute";
						$('block_nextstep').style.top = document.documentElement.scrollTop + 10 + "px";
					}
				}
			}
		});
	}
});

// Splash page 

Position.getWindowSize = function(w) {
	var array = [];
	
	array.width = array[0] = (document.documentElement.clientWidth || document.documentElement.scrollWidth);
	if (document.documentElement.scrollHeight < document.documentElement.clientHeight)
	{
		array.height = array[1] = document.documentElement.clientHeight;
	}
	else
	{
		array.height = array[1] = document.documentElement.scrollHeight;
	}
	
	return array;
}

function posTop() 
{
	return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}


function showSplash() {
	
	$('splash_overlay').style.width = Position.getWindowSize().width + 'px';
	$('splash_overlay').style.height = Position.getWindowSize().height + 'px';
	$('splash_overlay').show();
	$('splash').show();
}

function selectRegion(region) {
	var displayed = 0;
	$$("#splash_cities .splash_cities_hidden").each(function(){
		displayed++;
    });
	
	if (displayed < 4)
	{
		for (i=1;i<=4;i++)
		{
			if ($('splash_cities_' + i).className != "splash_cities_hidden" && i != region)
			{
				$('splash_regions_disabled').show();
				$('splash_regions_link' + i).removeClassName("splash_regions_selected");				
				Effect.BlindUp('splash_cities_' + i, {
					duration:0.5,
					afterFinish: function(){
						$('splash_cities_' + region).addClassName("splash_cities_hidden");
						$('splash_regions_disabled').hide();
						}
				});
			}
		}
		setTimeout(function(){
			if ($('splash_cities_' + region).className != "")
			{
				$('splash_regions_disabled').show();
				$('splash_regions_link' + region).addClassName("splash_regions_selected");
				Effect.BlindDown('splash_cities_' + region, {
								 duration:0.5,
								 afterFinish: function(){
										$('splash_regions_disabled').hide();
									 }
								 });
				$('splash_cities_' + region).removeClassName("splash_cities_hidden");
			}
		}, 550);
	}
	else
	{
		$('splash_regions_disabled').show();
		$('splash_regions_link' + region).addClassName("splash_regions_selected");
		Effect.BlindDown('splash_cities_' + region, {
						 duration:0.5,
						 afterFinish: function() {
							 	$('splash_cities_' + region).removeClassName("splash_cities_hidden");
								$('splash_regions_disabled').hide();
							 }
						 })
	}
}

function goTop()
{
	try{scroll(0,0)}
	catch(e){}			
};

var IframeHandlers = 
{
	IFRAME_MARGIN_B : 30,
	DOCUMENT_DOMAIN : 'lasikmd.com',
	
	goTop : function()
	{
		try{scroll(0,0)}
		catch(e){}			
	},
	
	_autoresize : function(isScroll)
	{
		if(isScroll)
		{
			IframeHandlers.goTop();
		}
	
		if(document.domain.split(IframeHandlers.DOCUMENT_DOMAIN).length == 2)
		{
			document.domain             = IframeHandlers.DOCUMENT_DOMAIN;
			var renderedDocumentHeight  = IframeHandlers.iframe.contentWindow.document.body.scrollHeight;  
			var iframeHeight            = renderedDocumentHeight + IframeHandlers.IFRAME_MARGIN_B + 'px';
			
			try
			{
				console.log('Iframe height :');
				console.log(iframeHeight);
			} catch(e){}
			
			IframeHandlers.iframe.setStyle({height : iframeHeight});

			return true;
		}
		
		return false;
	},
	
	autoresize : function(iframe)
	{
		IframeHandlers.iframe = iframe;
		IframeHandlers.iframe.observe('load', IframeHandlers._autoresize.curry(true));
       	new PeriodicalExecuter(IframeHandlers._autoresize.curry(false), 3); 
	}
};


function replaceInk(ink)
{
	location.hash = ink;
}
