/*
 * Main JS
 * Copyright (c) 2010  Oliver Astrologo
 * Dual licensed under MIT and GPL.
 * @author  Oliver Astrologo
 * @version 1.0
 */ 
 
  var is_ie6 = jQuery.browser.msie && (jQuery.browser.version < 7);
	   
	   
	
 
 jQuery(function() {
	

	/*jQuery("a[rel].thickbox").overlay({

		mask: 'darkred',
		effect: 'apple',
		onBeforeLoad: function() {
			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");
			// load the page specified in the trigger
			//wrap.load(this.getTrigger().attr("href"));			
			wrap.html('<img src="'+this.getTrigger().attr("href")+'" alt=" " />');
		}

	});*/
      jQuery(".products-list li,.related-list  li,.bigTarget").mouseover(function(){jQuery(this).addClass('over');}).mouseout(function(){jQuery(this).removeClass('over');}).click(function() {if (jQuery(this).find("a").length > 0){window.location = jQuery(this).find("a:first").attr('href');}});
//	jQuery("ul.tabs").tabs("div.pane",{current:"current",effect: 'fade'});
	jQuery("a.fancy").fancybox();

	jQuery('a.dialogX').click(function() {
            var url = this.href;
            var title = this.title;
		var dialog = jQuery('<div style="display:hidden"></div>').appendTo('body');
		// load remote content
		dialog.load(
			url, 
			{},
			function (responseText, textStatus, XMLHttpRequest) {
				dialog.dialog({
					modal: true,
					height: 400,
					width: 550,
					title: title,
					buttons: {
						Ok: function() {
							jQuery(this).dialog("close");
							}
						},
					close: function() {
						jQuery(this).empty();
						}
					});
				}
			);
		//prevent the browser to follow the link
		return false;
		});

	jQuery('a.dialog').click(function() {
            var url = this.href;
            var title = this.title;
		var dialog = jQuery('<div class="dyndialog" style="display:hidden"><p>Caricamento in corso...</p></div>').appendTo('body');
		dialog.dialog({
			modal: true,
			height: 350,
			width: 550,
			title: title,
			resizable: false,
			open: function() {
				dialog.load(url);
				}, 
			buttons: {
				},
			close: function() {
				dialog.remove();
//				jQuery(this).empty();
				}
			});
		//prevent the browser to follow the link
		return false;
		});


	jQuery.tools.dateinput.localize("it",  {
		months:        'gennaio,febbraio,marzo,aprile,maggio,giugno,luglio,agosto,settembre,ottobre,novembre,dicembre',
		shortMonths:   'gen,feb,mar,apr,mag,giu,lug,ago,set,ott,nov,dic',
		days:          'domenica,luned&igrave;,marted&igrave;,mercoled&igrave;,gioved&igrave;,venerd&igrave;,sabato',
		shortDays:     'dom,lun,mar,mer,gio,ven,sab'
		});
	jQuery(".dateinput,.dateinput2").dateinput({lang: 'it',  firstDay: 1,  trigger: true, format: 'dd/mm/yyyy', max: 60 })
//	jQuery(".dateinput").bind("onShow onHide", function()  {
//		jQuery(this).parent().toggleClass("active"); 
//		});

//	jQuery(".dateinput").dateinput();


	jQuery("#modify-button").show();

/*	jQuery("#modify-button-container").mouseenter(function(){
		if (jQuery("#modify-button").is(':hidden')) {
			jQuery("#modify-button").slideDown("fast")
			}
		}).mouseleave(function(){
		if (jQuery("#modify-button").is(':visible')) {
			jQuery("#modify-button").delay(2000).slideUp("slow");
			}
		});
*/


	$(".confirm-delete").confirm_prompt('Sei sicuro di voler rimuovere questo prodotto?');


	// Associa una funzione onChange ad alcune select.
	jQuery("#SwitchUser").change(function() {window.location = jQuery(this).attr('value');});


});


$.fn.confirm_prompt = function(stringa) {
	newlocation = $(this).get(0);
	this.click(function() {
		if (confirm(stringa)) {
			window.location = newlocation;
			}
		else{
			return false;
			}
		});
	}


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */


jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 1000 * 60 * 60 ));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

