
/*
Copyright © Lead eCommerce www.leadecom.com, 2010
*/

jQuery.noConflict();

jQuery(document).ready(function($){
	
	$("#cpanel td ul").each(function(){
		var showButton = false;
		var _ul = $(this);
		for(var i = 0, maxi = 6, obj = $("li",_ul); i < obj.length - 1; i++)
		{
			if( i > maxi - 1 )
			{
				$(obj[i]).hide();
				showButton = true;
			}
		}
		if(showButton)
		{
			$(".go",$(this)).click(function(){
				var _go = $(this);
				$("li",$(this).parent()).fadeIn();
				_go.hide();
				resizeCPanel( ($("li",_go.parent()).first().height()+15) *  $("li",_ul).length + 40 )
				return false;
			}).show();
		}
	});
	
	function resizeCPanel( cpheight )
	{
		if( ($('#cpanel').height()-59) < cpheight )
		{
			$('#cpanel ul').height(cpheight-59);
			$('#doctor').height(cpheight);
		}
	}
	
	resizeCPanel( $('#cpanel').height() );
	
	$('input.vin').focus(function(){
		if( $(this).attr('value') == $(this).attr('title') )
		{
			$(this).attr('value','');
		}
	});
	$('input.vin').blur(function(){
		if( !$(this).attr('value') )
		{
			$(this).attr('value',$(this).attr('title'));
		}
	});
	$('#search .searchbox form').submit(function(){
		return checkSearchForm( $('input.vin', $(this)) );
	});
	
	var currentTube = null;
	
	function toShowTube()
	{
		$("#flashtube")[0].HideTube( currentTube );
		currentTube = Math.round( Math.random() * 10 );
		$("#flashtube")[0].ShowTube( currentTube );
	}
	
	$('#flashzone .controll a, #cpanel li').mouseover(function(){
		currentTube = Math.round( Math.random() * 10 );
		$("#flashtube")[0].ShowTube( currentTube );
	});
	$('#flashzone .controll a, #cpanel li').mouseout(function(){
		$("#flashtube")[0].HideTube( currentTube );
	});
	
	$('#subscribe form').submit(function(){
		var e = $('input.vin', $(this));
		var value = e.attr('value');
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		
		if (!filter.test(value)) {
			alert("Wrong E-mail!");
			e.focus();
			return false;
		}
	});

	// Loading Modules
	
	try{$.iTabs([$('#TestMenu')])}catch(err){}
	
	try{$.wordShow(
		$("#topLine .topWord"),
		$("#topWord p"), {
			startItem:0,
			interval:4000
		}
	)}catch(err){}

	try{$.iOpenBox([$('div.newsline .caption')])}catch(err){}

	try{$.iRadioBox([
		{"rb":$("#iRadioGroup1"),"noTitle":false},
		{"rb":$("#iRadioGroup2"),"noTitle":false},
		{"rb":$("#iRadioGroup3"),"noTitle":false},
		{"rb":$("#iRadioGroup4"),"noTitle":false},
		{"rb":$("#iRadioGroup5"),"noTitle":false},
		{"rb":$("#iRadioGroup6"),"noTitle":false},
		{"rb":$("#iRadioGroup7"),"noTitle":false},
		{"rb":$("#iRadioGroup8"),"noTitle":true},
		{"rb":$("#iRadioGroup9"),"noTitle":true},
		{"rb":$("#iRadioGroup10"),"noTitle":true},
		{"rb":$("#iRadioGroup11"),"noTitle":true},
		{"rb":$("#iRadioGroup12"),"noTitle":true},
		{"rb":$("#iRadioGroup13"),"noTitle":true}
	])}catch(err){}
	
	try{$(".cplace .calendar").calendar("appointment_getDates.asp","appointment_getTimes.asp")}catch(err){}

	$('.content .submit').click(function(){
		$(this).parent().submit();
		return false;
	});
	$('.goToSubscribe').click(function(){
		$("#subscribe").fadeOut(function(){
			$(this).fadeIn(function(){
				$("input.vin",$(this)).focus();
			});
		});
		return false;
	});
	$('.flatForm .page .go').click(function(){
		var curr = $(this).parent();
		var next = curr.next();
		if( next.html() == null )
		{
			//$('.flatForm').submit();
		}
		else
		{
			//sl
			curr.fadeOut(function(){
				next.fadeIn(function(){
					var targetOffset = $(this).offset().top;
					$('html,body').animate( { scrollTop : targetOffset - 10 }, 'fast' );
				});
			})
			return false;
		}
		//return false;
	});

});



function checkSearchForm( e )
{
	var searchString = e.val();

	e.val( searchString == null ? "" : searchString.replace(/[\xA0-\xBF]|#|`|™/g,'').replace(/"|"|"/g,'"').replace(/'|'|‚/g,"'") );
		
	if( e.val().length < 2 || e.val() == e.attr('title') )
	{
		alert("Wrong inquiry!");
		return false;
	}
	
	return true;
}


