/* JQueryString v1.6.1
   By James Campbell 
   Many thanks to Mike Willis for his suggestions and additions to this jQuery plugin.
*/
(function($) {
$.getAllQueryStrings = function(options){
	defaults = {DefaultValue:"undefined", URL:window.location.href} ;
	options = $.extend(defaults , options);
	var qs;
	var args = new Array();
	if(typeof(options.URL.split( "?" )[1]) != "undefined"){
		qs = options.URL.split( "?" )[1].replace(/\+/g, ' ').split('&');
		$.each(qs, function(i){
			var currentArg = this.split('=');
			if(currentArg.length == 2){		
				args[i] = {name:currentArg[0], value:currentArg[1]};
				args[currentArg[0]] = {name:currentArg[0], value:currentArg[1]};
			}else{
				args[i] = {name:currentArg[0], value:currentArg[1]};
				args[currentArg[0]] = {name:currentArg[0], value:currentArg[0]};
			}
		});
	}
	if (args.length <= 0) {};
	return args;
}
$.getQueryString = function(options)
{
	defaults = {DefaultValue:"undefined", URL:window.location.href} ;
	options = $.extend(defaults , options);
	if(typeof($.getAllQueryStrings({URL:options.URL})[options.ID]) == "undefined"){
		return options.DefaultValue;
	}else{
		return $.getAllQueryStrings({DefaultValue:options.DefaultValue, URL:options.URL})[options.ID].value;
	}
};
})(jQuery);

jQuery.fn.equalHeight = function () {
    var height        = 0;
    var maxHeight    = 0;

    // Store the tallest element's height
    this.each(function () {
        height        = jQuery(this).outerHeight();
        maxHeight    = (height > maxHeight) ? height : maxHeight;
    });

    // Set element's min-height to tallest element's height
    return this.each(function () {
        var t            = jQuery(this);
        var minHeight    = maxHeight - (t.outerHeight() - t.height());
        var property    = jQuery.browser.msie && jQuery.browser.version < 7 ? 'height' : 'min-height';

        t.css(property, minHeight + 'px');
    });
};

// funzione per il resize del backgound canvas
// funzione per il resize del backgound canvas
var drawBackground = false; 
 
$(window).load(function(){ 
  drawBackground = true; 
  window.setTimeout(function(){ 
  if (drawBackground){drawBackground = false; DrawBackground();}}, 50); 
}); 


$(window).resize(function()  {
  test = $(window).height();
  $(".myoverlay, .myoverlayContatti, .myoverlayPrivacy").css("height",test + "px");
  drawBackground = true;
  window.setTimeout(function(){ 
  if (drawBackground){drawBackground = false;DrawBackground();}}, 50); 
}); 


// Apertura Document ready*******************************************
// Apertura Document ready*******************************************
// Apertura Document ready*******************************************
$(document).ready(function() { 
// Apertura Document ready*******************************************
// Apertura Document ready*******************************************
// Apertura Document ready*******************************************


if( location.href.match("Home") ) { 
   $('#Body').addClass('Home');
}

if (location.href == "http://www.tognicostruzioni.it/portal/") { 
   $('#Body').addClass('Home');
}

if (location.href == "http://www.tognicostruzioni.it/portal/Default.aspx") { 
   $('#Body').addClass('Home');
}


$('.container img').attr('alt', 'edit').parent('a').addClass('EditUdt');

$('#dnn_dnnNAV_ctldnnNAVctr7 a, #dnn_dnnNAV_ctldnnNAVctr41 a').remove();


$('#header div:first').addClass('MineNav');

$('#houseMenuVstatic li a[title=Servizi]').addClass('Servizi');
$('#houseMenuVstatic li a[title=Il Gruppo]').addClass('Gruppo');
$('#houseMenuVstatic li a[title=La Romagna]').addClass('Romagna');




$("ul").each(function(index) {
  $(this).find("li:last").addClass('lastItem');
});

$("ul").each(function(index) {
  $(this).find("li:first, li.CaseLi:first").addClass('firstItem');
  $(this).find("li:last, li.CaseLi:last").addClass('lastItem');
});

$(".lastItem").prev().addClass('prevlastItem');


$('ul.CaseUdt li.CaseLi:even').addClass('Odds');


$(".DoubleLeftPane .container:first").addClass('first');
$(".DoubleLeftPane .container:last").addClass('last');



$('li#houseMenuParentItem.lastItem').parent('ul').addClass('OneItem');

$(".CaseSlide ul,.CaseSlideDetail ul").each(function(index) {
  $('img[src="/portal/MakeThumbnailEx.ashx?image=&w=181&hcrop=125"], img[src="/portal/MakeThumbnailEx.ashx?image=&h=125&wcrop=181"],img[src="/portal/MakeThumbnailEx.ashx?image=&h=305&wcrop=399"] ').parent('li').addClass('hide');
   $('.CaseSlide ul li.hide,.CaseSlideDetail ul li.hide').remove();
});

$(".paginetesto").each(function(index) {
  $('img[src="/portal/DesktopModules/UserDefinedTable/MakeThumbnail.ashx?image=&w=580&"]').remove();
});

$(".CaseSlide ul li a.lente, .PortSlide ul li a.lente,.CaseSlideDetail ul li a.lente, a.organigramma").prettyPhoto({theme:'dark_square',opacity: 0.90,padding: 0, showTitle: false});


$("h4#contactinfo").hover(
  function () {
    $(this).addClass("moreInfoH");
  },
  function () {
    $(this).removeClass("moreInfoH");
  }
);

$('.UDT_Form #dnn_ctr404_Default_Form_cmdCancel, .UDT_Buttons span, #dnn_dnnNAV_ctldnnNAVctr68').remove();
$("#dnn_ctr409_Default_Form_cmdUpdate").addClass('more');



Cufon.replace('h1, h2, h4, #subOpen a, #subClick a, #TopPage, a.more, #sideSlider p, #houseMenuParentItem, #houseMenuVstatic li, .paginetesto .sottotitolo', {hover: true});

Cufon.replace('.MineNav ul li , #NavBottom ul li,', {
  textShadow: '#FFF 1px 1px',
  hover: true
});

$("#slider").easySlider({
	numeric: true,
  auto: true,
  continuous: true,
  speed: 800,
  pause: 6000
});


$(".CaseUdt li,.VenditaDettaglio").each(function(index) {
 $(this).find(".CaseSlide, .CaseSlideDetail").easySlider({numericId: 'C' + index, numeric: true,continuous: false,speed: 800,pause: 3000});
 $(this).find("ol li a").text('-');
 $(this).find("ol").addClass('fotoNav');
});

$('.Home ul.CaseUdt li.CaseLi:even').addClass('Odds');




$('.UDT_Type_Boolean span').replaceWith($('.UDT_Type_Boolean span').html());



$(".UDT_Form #dnn_ctr409_Default_Form_cmdUpdate").text('Invia messaggio');

  $('.UDT_Form input, .UDT_Form textarea').focus(function(){
    $(this).parents('.UDT_Field').addClass('hideLabel');
    }).blur(function(){
    $(this).parents('.UDT_Field').removeClass('hideLabel');
  });	
  
  $('.UDT_Form input, .UDT_Form textarea').change(function(){
  $(this).parents('.UDT_Field').addClass('HideComplete');
  });
  

$(".PagLeftDis, .PagLeft").text('Pagina precedente');
$(".PagRightDis, .PagRight").text('Pagina successiva');

$('a.PagRight, a.PagLeft').parents('table').addClass('visible');
$('table.PagingTable:not(.visible)').remove();

Cufon.replace('.PagLeftDis, .PagLeft, .PagRightDis, .PagRight, .PagLeftA, .PagRightA', {hover: true});


sName = $.getQueryString({ ID:"name" });




if( location.href.match("name=") ) { 
   $('.UDT_Type_TextHtml').addClass('hideLabel');
   $(".UDT_Input textarea").val(sName);
}






$("#contwith").backgroundCanvas();
$(".Home #contwith").backgroundCanvas();
$("#footerwidth").backgroundCanvas();
$(".HeaderPane .containerCanvas").backgroundCanvas();
	$(window).load(function () { DrawBackground();});  
    $(window).resize(function() { DrawBackground();});
	

// Chiusura Document ready*******************************************
// Chiusura Document ready*******************************************
// Chiusura Document ready*******************************************
});
// Chiusura Document ready*******************************************
// Chiusura Document ready*******************************************
// Chiusura Document ready*******************************************


function DrawBackground() {
	$("#contwith").backgroundCanvasPaint(bg_body);
	$(".Home #contwith").backgroundCanvasPaint(bg_bodyHome);
	$("#footerwidth").backgroundCanvasPaint(bg_footer);
	$(".HeaderPane .containerCanvas").backgroundCanvasPaint(bg_header)
}


// Subscribe Paint*********************************************


function bg_body(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) {  
	var options = {x:0, y:0, height: height, width: width, radius:0,  border: 0 };  
	
	options.height = 194;
	context.fillStyle   = '#CCC';
	$.canvasPaint.roundedRect(context,options);
	
	options.height = 193;
	context.fillStyle   = '#DEDEDE';
	$.canvasPaint.roundedRect(context,options);
	
	options.y = 195;
	options.height = 150;
	var backgroundGradient1 = context.createLinearGradient(0, 0, 0, 150);
    backgroundGradient1.addColorStop(0, '#F1F1F1');
    backgroundGradient1.addColorStop(1, '#FFF');
    context.fillStyle = backgroundGradient1;
    $.canvasPaint.roundedRect(context, options);

	
	var img = new Image();
    img.onload = function() {
    context.drawImage(img, Math.round((width / 2) - 600), 0);
    };
    img.src = "/portal/Portals/_default/Skins/togni/images/togni_gradientLogo.png";
}

function bg_bodyHome(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) {  
	var options = {x:0, y:0, height: height, width: width, radius:0,  border: 0 };  
	
	options.height = 355;
	context.fillStyle   = '#CCC';
	$.canvasPaint.roundedRect(context,options);


	
	options.height = 354;
	context.fillStyle   = '#DEDEDE';
	$.canvasPaint.roundedRect(context,options);
	
	options.y = 357;
	options.height = 50;
	var backgroundGradient1 = context.createLinearGradient(0, 0, 0, 50);
    backgroundGradient1.addColorStop(0, '#F1F1F1');
    backgroundGradient1.addColorStop(1, '#FFF');
    context.fillStyle = backgroundGradient1;
    $.canvasPaint.roundedRect(context, options);

	
	var img = new Image();
    img.onload = function() {
    context.drawImage(img, Math.round((width / 2) - 600), 0);

    };

    img.src = "/portal/Portals/_default/Skins/togni/images/togni_gradientLogo.png";

	
}


function bg_footer(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) {  
	var options = {x:0, y:0, height: height, width: width, radius:0,  border: 0 };  
	
	context.fillStyle   = '#DEDEDE';
	$.canvasPaint.roundedRect(context,options);


	options.height =20;
	var backgroundGradient1 = context.createLinearGradient(0, 0, 0, 10);
    backgroundGradient1.addColorStop(0, '#C8C8C8');
    backgroundGradient1.addColorStop(1, '#DEDEDE');
    context.fillStyle = backgroundGradient1;
    $.canvasPaint.roundedRect(context, options);

	
}


function bg_header(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) {  
	var options = {x:0, y:0, height: height, width: 980, radius:0,  border: 0 };  
	
	
	var backgroundGradient1 = context.createLinearGradient(0, 0, 0, height);
    backgroundGradient1.addColorStop(0, '#CCC');
    backgroundGradient1.addColorStop(0.8, '#CCC');
	backgroundGradient1.addColorStop(1, '#FFF');
    context.fillStyle = backgroundGradient1;
    $.canvasPaint.roundedRect(context, options);

	options.y = 1;
	options.x = 1;
	options.height = height-1;
	options.width = width-2;
	context.fillStyle   = '#FFF';
	$.canvasPaint.roundedRect(context,options);

	
}








