	jQuery(function(){
		if(jQuery.cookie('my_stock') != null && jQuery.cookie('my_stock') != "")
		{
			ajaxGetCall('getQuotes', jQuery.cookie('my_stock'), 'pane2');
			colorizeStock();
		}else{
			jQuery('#pane2').css({'height':'118px'});
			colorizeStock();
			addScroll();
		}
		
		jQuery('.stock-changer-w a.stock-city-state').click(function(event){
			event.preventDefault();
			jQuery('.stock-togler-a').fadeOut(function(){
				jQuery('.stock-togler-b').fadeIn();
				desapireText();
			});
			
		});	
		jQuery('#stock-swich-b-id').click(function(event){
			event.preventDefault();
			clearValues();
			jQuery('.stock-togler-b').fadeOut(function(){
				jQuery('.stock-togler-a').fadeIn();
				desapireText();				
			});
		});	
		jQuery('#stock-finder').click(function(event){
			event.preventDefault();
			if(jQuery('#stock-place').val() != "")
			{
				jQuery('.helper-stock').text("");
				jQuery('#stock-place').css({'border':'1px solid #ccc'});
				ajaxFindCall('findCompanies', jQuery('#stock-place').val(), 'selectSt');
			}
			else
			{
				jQuery('#stock-place').css({'border':'1px solid red'});
				jQuery('.helper-stock').text("you must enter some value");
			}
		})
		jQuery('#stock-swich-a-id').click(function(event){
			event.preventDefault();
			var symbol = jQuery('#company_symbol').val();
			if(checkIfExists(symbol) == 0 && symbol != '')
			{
				ajaxGetCall('getQuotes', symbol, 'pane2');
			}
			else
			{
				if(symbol == '')
				{
					jQuery('.helper-stock').text("you must select from the dropdown");
				}
				else
				{
					jQuery('.helper-stock').text('you alredy have this result');
				}
			}
		})
		jQuery('.stock-swicher-d a').click(function(event){
			event.preventDefault();
			jQuery('.stock-swicher-d a').removeClass('stock-active-metric');
			jQuery(this).addClass('stock-active-metric');
		})
		jQuery('.selectSt').change(function(){
			jQuery("select option:selected").each(function () {
					str = jQuery(this).val();
				});
			jQuery("#company_symbol").val(str);
		})
		initRemovStock();
		 //emptyStock();
	})
	
	function ajaxFindCall(action, query, div)
	{
		jQuery.ajax({
			type: 'POST',
			url: urlStock+'/wp-content/plugins/bankSite-stock/consumer.php',
			data: 'action='+action+"&query="+query,
			success: function(data) 
			{
				jQuery("."+div).html(data);
				jQuery(".selector span").text(jQuery('.selectSt option:first').text()); 
				jQuery("#company_symbol").val(jQuery('.selectSt option:first').val());
				jQuery('.helper-stock').text("");
				jQuery('.selectSt').removeAttr("disabled");
			}
		});
	}
	
	function ajaxGetCall(action, query, div)
	{
		jQuery.ajax({
			type: 'POST',
			url: urlStock+'/wp-content/plugins/bankSite-stock/consumer.php',
			data: 'action='+action+"&query="+query,
			success: function(data) 
			{
				jQuery("#"+div).append(data);
				jQuery('.stock-togler-b').fadeOut(function(){
					jQuery('.stock-togler-a').fadeIn();	
					addScroll();
					initRemovStock();
					clearValues();
					setCookie();
					colorizeStock();
					jQuery('.selectSt').attr("disabled", "disabled");
				});
			}
		});
	}
	function addScroll()
	{
	
		jQuery('#pane2 div.stock-stockIcon').each(function(i){
			
			if(jQuery('.stock-stockIcon').size() > 3){
				jQuery('#pane2').jScrollPane({showArrows:true});
				jQuery('.right-info').css({'width':'47px'});
				jQuery('.stock-result-wraper div.markerStock').css({'margin-left':'4px'});
				jQuery('.stock-result-wraper div.remover').css({'margin-right':'0px'});
			}else{
				jQuery('#pane2').jScrollPaneRemove();
				jQuery('.right-info').css({'width':'59px'})
				jQuery('.stock-result-wraper div.markerStock').css({'margin-left':'18px'});
				jQuery('#pane2').css({'height':'118px'});
				jQuery('.stock-result-wraper div.remover').css({'margin-right':'-3px'});
			}
		})
	}
	
	function checkIfExists(selected)
	{	
		var isIt = 0;
		jQuery('span.info-simbol').each(function(i){
			if(jQuery(this).text() == selected)
			{
				isIt++;
			}
		})
		return isIt;
	}
	
	function clearValues()
	{
		jQuery('#stock-place').css({'border':'1px solid #ccc'});
		jQuery('#stock-place').val("");
		jQuery('#company_symbol').val("");
		jQuery('.helper-stock').text("");
		jQuery('.selector span').text("");
		jQuery('.selectSt').children().remove();
	}
	
	function setCookie()
	{
		var myStocks = "";
		jQuery('span.info-simbol').each(function(i){
			myStocks += ", "+jQuery(this).text();
		})
		jQuery.cookie("my_stock", myStocks, { expires: 90});
	}
	function colorizeStock(){
		/*jQuery('.stock-stockIcon:first-child').not('.stock-stockIcon div').addClass('First-color');
		jQuery('.stock-stockIcon').not('.stock-stockIcon:first-child').addClass('baseBgColor');
		jQuery('.First-color div.stock-result-wraper div.right-info div.markerStock').addClass('baseBgColor');
		jQuery('.baseBgColor div.stock-result-wraper div.right-info div.markerStock').addClass('First-color');*/
		jQuery('.stock-stockIcon').not('.stock-stockIcon div').addClass('baseBgColor');
		jQuery('div.stock-result-wraper div.right-info div.markerStock').addClass('First-color');
	}
	
	function initRemovStock(){
		jQuery('.remover').click(function(){
			jQuery(this).parent().parent().fadeOut(function(){
				jQuery(this).remove();
				addScroll();
				setCookie();
			});
		});	
	}
	
	function desapireText(){
		jQuery('#stock-place').val(" enter number or name");
		jQuery("#stock-place").focus(function () {
			if (this.value == ' enter number or name'){
				jQuery(this).removeClass('text-s');
				jQuery(this).val("");
			}
		});
		jQuery("#stock-place").blur(function () {
			if (this.value == ''){
				jQuery(this).addClass('text-s');
				jQuery(this).val(" enter number or name");
			}
		});
	}
