$(document).ready( function() {
	/*$("a.toggle").click(function(){
		$(this).parent().find(".front_hide").toggle();
		return false;
	});*/
	$("#order_form").click(function(){
		showForm('alert'); return false; 
	});
	$("#call_form").click(function(){
		showForm('call_form'); return false; 
	});
	$(".content-view-embed .class-image .attribute-image img").wrap(function(){
		var array = [ 'tiny',
		              'small',
		              'medium',
		              'listitem',
		              'articleimage',
		              'articlethumbnail',
		              'gallerythumbnail',
		              'galleryline',
		              'imagelarge',
		              'rss',
		              'infoboximage',
		              'billboard',
		              'on_main',
		              'product',
		              'product_line',
		              'news_line',
		              'news_line_front',
		              'right_menu',
		              'reference' ];
		src=$(this).attr('src').replace('_tiny.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_small.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_medium.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_listitem.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_articleimage.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_articlethumbnail.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_gallerythumbnail.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_galleryline.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_imagelarge.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_large.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_rss.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_logo.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_infoboximage.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_billboard.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_on_main.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_product.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_product_line.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_news_line.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_news_line_front.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_right_menu.','.');
		if ($(this).attr('src')==src)
			src=$(this).attr('src').replace('_reference.','.');
		
		return '<a rel="prettyPhoto[gallery1]" href="' + src + '"  target="_self" />';
	});
	$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
	$("#submut_tracker").click(function(){
		rwIDval = $("input#tracker").val();
		$.ajax({
			  type: 'POST',
			  url: '/ezjscore/call/ezjsccalc::xmlResutTracker',
			  data: {"rwID":rwIDval},
			  dataType:"json",
			  success: function(data){
				  $("#orderWarning").toggle();
				  $("#result").append('<p class="error tracker">'+data['content']['header']+'</p>');
			  }
			});
		return false;
	});
});

function showNext(attr_id){
	prev_id = attr_id-1;
	$("#enhancedfile"+attr_id).toggle();
	$("#enhancedfile"+prev_id+"_add").toggle();
}
function showNextPhone(attr_id){
	next_id = attr_id+1;
	$("#phone_set_"+next_id).toggle();
	$("#phone_set_"+attr_id+"_add").toggle();
}
function removePop (){
	$("#popup").remove();
	$(".popup_overlay").remove();
	$("a.to_order").removeAttr("disabled")
}
function showForm (formName){
	$("a.to_order").attr("disabled","disabled");
	$.get('/ezjscore/call/ezjsctemplate::'+formName, function(data) {
		$("body").prepend("<div class='popup_overlay'></div><div id='popup'></div>");
		$('div#popup').html(data);
	});
}
