 $.noConflict();
 



function set_size(sizeval,sizeelement)
{
	jQuery('.clearsize').each(function(index) {
		 jQuery(this).css('border','1px solid #6ca9bd'); 
	  });

	jQuery("input#size").val(sizeval); 
	jQuery("#"+sizeelement).css('border','1px solid red'); 


	if(jQuery("input#fileup").val())
	{
		jQuery("#various3").attr('href','/index.php/main/crop/'+jQuery("input#fileup").val()+'/'+sizeval+'/'+jQuery('input#fileid_main').val()+'/');
		jQuery("#various3").click();
	}

	jQuery("#font1").attr('href','/index.php/main/fontselect/1/'+sizeval+'/');

	apply_changes();
	
}


function set_grad1(gradval)
{
	jQuery("input#grad1").val(gradval); 

	apply_changes();
}

function set_grad2(gradva2)
{
	jQuery("input#grad2").val(gradva2); 

	apply_changes();
}

function set_border_color(bcolor)
{
	jQuery("input#border_color").val(bcolor); 
	
	if(jQuery("input#border").val()==0)
	{
		jQuery("input#border").val(1); 
		A_SLIDERS[0].f_setValue(1);
	}
	apply_changes();
}



function remove_uploaded()
{
	jQuery("input#fileup").val(''); 

	apply_changes();
	reupfile();
}




function reset_1()
{
	A_SLIDERS[0].f_setValue(0);
	A_SLIDERS[1].f_setValue(0);
	A_SLIDERS[2].f_setValue(0);

}

function reset_2()
{
	A_SLIDERS[3].f_setValue(0);
	A_SLIDERS[4].f_setValue(0);
	A_SLIDERS[5].f_setValue(0);

}

function set_font_size(fontid,fontsize)
{
	
	jQuery("input#text_"+fontid+"_size").val(fontsize); 

	apply_changes();
}



function font_select(fontid,fontname)
{
	
	parent.jQuery("#font_preview_"+fontid).attr("src", "/other/des3/fonts/"+fontname+".jpg"); 
	parent.jQuery("input#text_"+fontid+"_font").val(fontname); 
	parent.apply_changes();
	
	parent.jQuery.fancybox.close();
	
}



function effect_set(effectid)
{
	
	jQuery("input#effect").val(effectid); 
	apply_changes();
}

function set_font_color(fontid,color)
{
	
	jQuery("input#text_"+fontid+"_color").val(color); 

	apply_changes();
}


function set_text(textid,text)
{
	
	jQuery("input#text_"+textid+"_text").val(text); 

	apply_changes();
}



function apply_changes()
{
	d = new Date(); 	
	
	//alert('applyed');
	
	jQuery.ajax({ 
			url: "/index.php/action/generate/"+d.getTime(), 
			type: 'POST', 
			beforeSend: function(){
				jQuery("#loader").css('top',(jQuery("#imageholder").height()/2)-20); 
				
				jQuery("#loader").show(); 
			},
			data: { 
					fileid: jQuery('input#fileid').val(),
					size: jQuery('input#size').val(),
					grad1: jQuery('input#grad1').val(),
					grad2:  jQuery('input#grad2').val(),
					fileup:  jQuery('input#fileup').val(),
					border:  jQuery('input#border').val(),
					border_color:  jQuery('input#border_color').val(),
					text_1_text:  jQuery('input#text_1_text').val(),
					text_1_color:  jQuery('input#text_1_color').val(),
					text_1_font:  jQuery('input#text_1_font').val(),
					text_1_size:  jQuery('input#text_1_size').val(),
					text_1_hor:  jQuery('input#text_1_hor').val(),
					text_1_ver:  jQuery('input#text_1_ver').val(),
					text_1_rot:  jQuery('input#text_1_rot').val(),

					text_2_text:  jQuery('input#text_2_text').val(),
					text_2_color:  jQuery('input#text_2_color').val(),
					text_2_font:  jQuery('input#text_2_font').val(),
					text_2_size:  jQuery('input#text_2_size').val(),
					text_2_hor:  jQuery('input#text_2_hor').val(),
					text_2_ver:  jQuery('input#text_2_ver').val(),
					text_2_rot:  jQuery('input#text_2_rot').val(),

					effect_ammount:  jQuery('input#effect_ammount').val(),
					effect:  jQuery('input#effect').val()
					}, 
			async: true, 
			timeout: 30000, 
			cache: false, 
			success: function(msg){  
				jQuery("#loader").hide(); 
				load_result(msg);
				//jQuery('#debug').html(msg);
				//jQuery("#loader").hide(); 
				//alert(msg);
				
				
			} 
		}); 

		
		
		jQuery("#border_info").html(jQuery("input#border").val()); 

		jQuery("#imgur_response").show();
		jQuery("#embedcodes").hide();
		jQuery("#imgur_response").html('<a href="javascript:;" onclick="imgur_up()"><img src="/other/des3/getcodes.gif" style="margin-left:10px;" border="0"/></a>');

}


function load_result(refreshval)
{
	jQuery("#loader").show(); 

	d = new Date(); 
	jQuery("#imageplace").attr("src", jQuery('input#fileid').val()+"?"+d.getTime()); 	


	jQuery('#imageplace').load(function() {
        jQuery("#loader").hide(); 
    });

	

}









function imgur_up()
{
	d = new Date(); 	
	
	//jQuery("#loader").hide(); 
	jQuery("#imgur_response").hide(); 
	jQuery("#loader2").show(); 

	jQuery.ajax({ 
			url: "/index.php/action/imgur_upload/"+d.getTime(), 
			type: 'POST', 
			data: { 
					fileid: jQuery('input#fileid_main').val()
					}, 
			async: true, 
			timeout: 30000, 
			cache: false, 
			success: function(msg){  
				//load_result(msg);
				//jQuery('#imgur_response').html(msg);
				
				jQuery('#embed1').val(msg);
				jQuery('#embed2').val('<a href="http://www.forumsigmaker.com" target="_blank"><img src="'+msg+'" border="0"/></a>');
				jQuery('#embed3').val('[URL=http://www.forumsigmaker.com][IMG]'+msg+'[/IMG][/URL]');
				jQuery('#embedcodes').show();
				
				jQuery("#dlimg").attr("href", "/index.php/action/img_dl/"+jQuery('input#fileid_main').val()); 
				jQuery("#imgur_link").attr("href", msg); 

				//jQuery("#loader").hide(); 
				
			} 
		}); 

		jQuery("#loader2").hide(); 
		//jQuery("#imgur_response").show(); 
}







	function ajaxFileUpload()
	{
		jQuery("#loading")
		.ajaxStart(function(){
			jQuery(this).show();
			jQuery("#loader").show(); 
			jQuery("#uploader").hide();
		})
		.ajaxComplete(function(){
			jQuery(this).hide();
			jQuery("#loader").hide(); 
		});
		

		jQuery.ajaxFileUpload
		(
			{
				
				url:'/index.php/action/upload/', 
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							alert(data.error);
						}else
						{
							//alert(data.msg);
							jQuery("input#fileup").val(data.msg);
							jQuery("input#fileup_orig").val('orig_'+data.msg);
							jQuery("#uploader_info").show();
							jQuery("#various3").attr('href','/index.php/main/crop/'+data.msg+'/'+jQuery('input#size').val()+'/'+jQuery('input#fileid_main').val()+'/');
							jQuery("#various3").click();
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)
		
		return false;

	}  


function reupfile()
{
	jQuery("#uploader_info").hide();
	jQuery("#uploader").show();

}

jQuery(document).ready(function() {
/*
	jQuery("#preloader").hide();
	jQuery("#contenttabhold").show();
*/
	jQuery('input#loaded').val('1');

	jQuery("#various3").fancybox({
		'width'				: '95%',
		'height'			: '95%',
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	jQuery("#font1").fancybox({
		'width'				: 820,
		'height'			: '95%',
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	jQuery("#font2").fancybox({
		'width'				: 820,
		'height'			: '95%',
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
});



 function init(){
	var stretchers = document.getElementsByClassName('box');
	var toggles = document.getElementsByClassName('tab');
	var myAccordion = new fx.Accordion(
		toggles, stretchers, {opacity: false, height: true, duration: 300}
	);
	//hash functions
	var found = false;
	toggles.each(function(h3, i){
		var div = Element.find(h3, 'nextSibling');
			if (window.location.href.indexOf(h3.title) > 0) {
				myAccordion.showThisHideOpen(div);
				found = true;
			}
		});
		if (!found) myAccordion.showThisHideOpen(stretchers[0]);
}


