var $j = jQuery.noConflict();

// tooltip init
$j(document).ready(function() {
		
        $j("[title]").each(
	   		function(i, el){									
				$j(el).simpletooltip();
			}
	   );
		
		$j(".treeview").each(function(i, el){
			$j(el).treeview({
				persist: "location",
				collapsed: true,
				unique: true
			});
		});
	   
	   $j(".temporary").each(
	   		function(i,el){
				$j(el).oneTime(10000, function() {					
				    $j(this).hide();
				  });
			}
	   );
	   
	   $j(".message").each(
	   		function(i,el){
	  			$j(el).dialog({width:900, height: 200, title:$j(el).attr('window'), modal: true, draggable:true,   resizable:true });
				$j(el).dialog( 'open' );
			}
	   );
	   
	    $j(".accordion").each(
	   		function(i,el){
	  			$j(el).accordion({autoHeight:false,clearStyle: true , animated:false});
			}
	   );
	   
	   $j(".progressbar").each(
	   		function(i,el){
	  			$j(el).progressbar({ value: $j(el).attr("value")?$j(el).attr("value"):0 });
			}
	   );
	   
	   $j(".slider").each(
	   		function(i,el){
	  			$j(el).slider({
					value: $j(el).attr("value") ? $j(el).attr("value") : 0,
					
					 slide: function(event, ui) { $j("#"+el.id+"_field").val(ui.value);}

				});
			}
	   );
	   
	   $j("*.popup").each(function(i,el){
	   		$j(el).click(
				function()
				{
					p_id="#"+$j(this).attr("window");					
					if($j(p_id).length<=0)
						$j(this).after("<div id='"+$j(this).attr("window")+"' style='display:none'></div>");															
					p_width=parseInt(($j(this).attr("window_width")?$j(this).attr("window_width"):100));
					p_height=parseInt($j(this).attr("window_height")?$j(this).attr("window_height"):100);
					p_resizeable=($j(this).attr("window_resizeable")?$j(this).attr("window_resizeable")=="true":true);
					p_draggable=($j(this).attr("window_draggable")?$j(this).attr("window_draggable")=="true":true);
					p_modal=($j(this).attr("window_modal")?$j(this).attr("window_modal")=="true":true);
					p_title=($j(this).attr("window_title")?$j(this).attr("window_title"):"");
					p_link=($j(this).attr("window_link")?$j(this).attr("window_link"):'');
					 
					this.dialog=$j(p_id).dialog({
						width:p_width,
						open: function(event, ui) {
							if(p_link){
								$j(p_id).load(p_link)
							} 
						}, 
						height: p_height, 
						title:p_title, 
						modal: p_modal, 
						draggable:p_draggable,  
						resizable:p_resizeable });
					this.dialog.dialog( 'open' );
				}
			);				   		
	   });
	   
	   $j("input.calendar").each(function(i,el){
	   		$j(el).datepick({ dateFormat: 'yy-mm-dd', yearRange:"-90:+10" });
	   });
	   
	   $j("input.spinner").each(function(i,el){
	   		$j(el).spinner();
	   });
	   $j("div.ddsmoothmenu").each(function(i,el){
	   		ddsmoothmenu.init({
				mainmenuid: el.id,				
				contentsource: "markup" 
			})
	   });
	   
	   $j("*.tabs_view").each(function(i,el){
	   		
			if($j(el).attr("select"))
			{		
				$j(el).tabs({ selected: $j(el).attr("select") });
			}
			else
				$j(el).tabs();
			$j(el).show();
	   });
	   
	   $j("*.slideshow").each(function(i,el){
	   		$j(el).carousel({
		      hide: 'fadeOut', // jquery show / hide effect method name
		      show: 'fadeIn', // jquery show / hide effect method name
		      duration: 500, // duration of wait in milliseconds
		      speed: 2000, // speed in milliseconds, 'slow' or 'fast',
		      seed: 5 // length of random classname applied to item to keep things all nice and seperate
		              // warning: setting this to something ridiculous will make it take ages to load.
		    });
			$j(el).show();
		});
	   
	   $j("*.expander").each(function(i,el){
	   		$j(el).click(
				function(){
					if ( $j(this).attr("expand") && $j("#"+$j(this).attr("expand")).get()!="") {
						if ($j("#"+$j(this).attr("expand")).is(':visible'))
							$j("#"+$j(this).attr("expand")).hide();
						else 
							$j("#"+$j(this).attr("expand")).show();
					}
					else {
						if ($j(this).next().is(':visible')) 
							$j($j(this)).next().hide();
						else 
							$j($j(this)).next().show();
					}
				}
			);	   		
	   });
	   
	   
	   $j("[hint]").each(function(i,el){
	   		$j(el).inputHintBox({attachTo:$j(el).parent(),className:'hint_box',source:'attr',attr:'hint',incrementLeft:0,incrementTop:0});			
			
	   });
});

function Validation(id,options)
{
	this.id=id;
	this.options=options;
	
	$j("#"+id).validate();
}


function ajax_load(url, pars, where, evalonsuccess) 
{
	$j.ajax({
			url: url,
			data: pars,
			cache: true,
			success: function(response){
				if(where!="")
					$j(where).html(response);
				eval(evalonsuccess);
			}
		});
}


function go_to(url)
{
	location.href=url;
	return false;
}

function edit(url,id)
{
	go_to(url+"?a=edit:"+id);
}

function del(url)
{
	if(confirm("Sunteti sigur ca doriti sa stergeti?"))
	{
		go_to(url);
	}
}

function cnf(message)
{
	return confirm(message);
}

function cart_add(product_id,quantity)
{
	if(product_id && quantity)
		go_to(root+"companii/cart?a=add&product_id="+product_id+"&quantity="+quantity);
}

function cart_save(product_id,quantity)
{
	if(product_id && quantity)
		go_to(root+"companii/cart?a=save&product_id="+product_id+"&quantity="+quantity);
}

function cart_delete(product_id,quantity)
{
	if(product_id)
		go_to(root+"companii/cart?a=delete&product_id="+product_id+"&quantity="+quantity);
}

function cart_empty()
{
	go_to(root+"companii/cart?a=empty");
}

function form_check_all(id, elem){
	$j("*:checkbox").each(
		
		function(i,el){
			el.checked=elem.checked;
		}
	);	
}


