jQuery(document).ready(function() {
 
    //speed rfp google analytics  click tracking workaround
    jQuery("#speedrfp_button_text").click(function() {       
        strippedUrl = stripUrl(srfp_widget.speedrfp_url);
        str = '/outgoing/' + strippedUrl;
       // alert(str)
        pageTracker._trackPageview(str);
    });
 
    //css the dropdown open in site editing
    jQuery('.languageChanger  li ul').css('display', 'none').css('position', 'absolute');


    window.pushDateVal = 1;  //put in rel attribute of #startdate or .numbernights field
    if (jQuery('#startdate').attr('rel') > 0) {
        window.pushDateVal = parseInt(jQuery('#startdate').attr('rel'));
    }

    if (jQuery("#startdate").length > 0) {

        if (dateFormat == "") {
            var dateFormat = "mm/dd/yyyy";
        }

        jQuery.datepicker.setDefaults({
            minDate: 0,
            buttonText: '&nbsp;&nbsp;&nbsp;',
            defaultDate: +1,
            showOn: 'both',
            buttonImageOnly: false//,
            //dateFormat: dateFormat

        });

        jQuery('#startdate').datepicker({

            onClose: function() {
                pushDate(window.pushDateVal);
            }


        });
        jQuery('#enddate').datepicker({
            beforeShow: minRange,
            defaultDate: +3
        });
    }
    if (jQuery('.languageChanger').length > 0) {
        jQuery('.languageChanger').singleDropMenu();
    }




    jQuery('.iframe_modal').live('click', function(e) {

        e.preventDefault();


        var dWidth = 800;
        var dHeight = 500;

        var $this = $(this);
        if ($this.hasClass('small')) {
            dWidth = 200;
            dHeight = 200;
        }
        if ($this.hasClass('large')) {
            dWidth = 860;
            dHeight = 600;
        }
        if ($this.hasClass('xlarge')) {
            dWidth = 930;
            dHeight = 500;
        }

        var thisDialogClass = '';
        if ($this.hasClass('noTitle')) {
            thisDialogClass = 'noTitle';
        }


        var horizontalPadding = 12;
        var verticalPadding = 0;



        theDialog = jQuery('<iframe  id="externalSite" class="externalSite" frameborder="0" src="' + this.href + '" />');
        theDialog.dialog({
            dialogClass: thisDialogClass,
            title: ($this.attr('title')) ? $this.attr('title') : 'Info',
            autoOpen: true,
            closeText: 'Close',
            width: dWidth,
            height: dHeight,
            modal: true,
            beforeclose: function() {
                $this.removeClass('disabled');
            },
            open: function(event, ui) {
                jQuery('body').css('overflow', 'hidden');
                jQuery('.ui-widget-overlay').css('width', '100%');
            },
            close: function(event, ui) { $('body').css('overflow', 'auto'); },
            closeOnEscape: false
        }).width(dWidth - horizontalPadding).height(dHeight - verticalPadding);



    });
    jQuery('.ui-widget-overlay').live('click', function() {

        // theDialog.dialog('close');

    });





    //put additional functions here.


});   //end ready

//pushes the endDate back to +2d of startdate
function pushDate(numberDaysAhead) {
    if (jQuery("#enddate").length > 0) {

        var startDate = jQuery("#startdate").datepicker("getDate");
        var endDate = jQuery("#enddate").datepicker("getDate");

        if (startDate > endDate) {
            startDate.setDate(startDate.getDate() + numberDaysAhead);
            jQuery('#enddate').datepicker('setDate', startDate);
            //alert('start gt end');
        } else {
            //alert('start lt end');
        }
    }
}

//customize mindate so that enddate cannot be b4 startdate
function minRange(input) {
    return {
        minDate: (jQuery("#startdate").datepicker("getDate") != null ? jQuery("#startdate").datepicker("getDate") : 2)
    };
}
//startdate cannot be after enddate
function maxRange(input) {
    return {
        maxDate: (jQuery("#enddate").datepicker("getDate") != null ? jQuery("#enddate").datepicker("getDate") : null)
    };
}


// SWFObject

var APPVERSION = "1.0.9";
var flashvars = {};
flashvars.APPVERSION = APPVERSION;
var params = {};
params.wmode = 'opaque';
params.allowscriptaccess = 'always';
params.allownetworking = 'true';
var attributes = {}; 

// Meetings Flash
swfobject.embedSWF("swf/DOLCE_MEETINGS_LOADER_ENGLISH.swf?APPVERSION="+APPVERSION, "flash_meeting", "822", "359", "9.0.0", "/_flash/swfobject/expressInstall.swf", flashvars, params, attributes);
swfobject.embedSWF("/_flash/DOLCE_MEETINGS_LOADER_FRENCH.swf?APPVERSION="+APPVERSION, "flash_meeting_fr", "822", "359", "9.0.0", "/_flash/swfobject/expressInstall.swf", flashvars, params, attributes);
swfobject.embedSWF("/_flash/DOLCE_MEETINGS_LOADER_SPANISH.swf?APPVERSION="+APPVERSION, "flash_meeting_sp", "822", "359", "9.0.0", "/_flash/swfobject/expressInstall.swf", flashvars, params, attributes);

// Explore Flash
swfobject.embedSWF("swf/DOLCE_EXPLORE_LOADER_ENGLISH_DM_071210.swf", "flash_explore", "822", "359", "9.0.0", "/_flash/swfobject/expressInstall.swf", flashvars, params, attributes);
swfobject.embedSWF("/_flash/DOLCE_EXPLORE_LOADER_FRENCH_DM_071210.swf", "flash_explore_fr", "822", "359", "9.0.0", "/_flash/swfobject/expressInstall.swf", flashvars, params, attributes);
swfobject.embedSWF("/_flash/DOLCE_EXPLORE_LOADER_SPANISH_DM_071210.swf", "flash_explore_sp", "822", "359", "9.0.0", "/_flash/swfobject/expressInstall.swf", flashvars, params, attributes);

// Weddings Flash
swfobject.embedSWF("swf/DOLCE_WEDDINGS_LOADER_ENGLISH_WR_071210.swf", "flash_wedding", "822", "359", "9.0.0", "/_flash/swfobject/expressInstall.swf", flashvars, params, attributes);
swfobject.embedSWF("/_flash/DOLCE_WEDDINGS_LOADER_FRENCH_WR_071210.swf", "flash_wedding_fr", "822", "359", "9.0.0", "/_flash/swfobject/expressInstall.swf", flashvars, params, attributes);
swfobject.embedSWF("/_flash/DOLCE_WEDDINGS_LOADER_SPANISH_WR_071210.swf", "flash_wedding_sp", "822", "359", "9.0.0", "/_flash/swfobject/expressInstall.swf", flashvars, params, attributes);
		
// Create Cookie
	function createCookie(value) 
    {
		var date = new Date();
		//date.setTime(date.getTime()+(30*24*60*60*1000)); //30 days
		//var expires = "; expires="+date.toGMTString();
		document.cookie = "footerCookie="+value+"; path=/";
	}

// Call Cookie
	var footerCookieValue = readCookie();
	function readCookie() 
    {
		var nameEQ = "footerCookie=";
		var ca = document.cookie.split(';');
		for(var i=0; i < ca.length; i++) 
        {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

// Calls the cookie and sets the bar as open or closed onLoad
	function init() 
    {
		//alert(footerCookieValue);
		var footerOpen   = document.getElementById("footer-float");
		var footerClosed = document.getElementById("footer-float-closed");
		if (footerCookieValue == "closed") 
        {
			footerOpen.style.display = "none";
			footerClosed.style.display = "block";
		} 
        else 
        {
			footerOpen.style.display = "block";
			footerClosed.style.display = "none";
		}
	}
	window.onload = init;

// Toggles the bar between open and closed
	function toggleBar() 
    {
		var footerOpen = document.getElementById("footer-float");
		var footerClosed = document.getElementById("footer-float-closed");
		var iframeWrapper = document.getElementById("iframe-wrapper");
		if (footerOpen.style.display == "block") 
        {
			footerOpen.style.display = "none";
			footerClosed.style.display = "block";
			iframeWrapper.style.display = "none";
			createCookie('closed');
		} 
        else 
        {
			footerOpen.style.display = "block";
			footerClosed.style.display = "none";
			iframeWrapper.style.display = "block";
			createCookie('open');
		}
	}
	
// Image preloader/swapper

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function openWindow(url) 
{
	window.open(url,'','resizable,scrollbars,width=800,height=600,top=500,left=500,toolbar=yes');
}
function openNewWindow() 
{
	MM_openBrWindow('http://www.dolcemunich.com/webview/default-en.asp','popup','width=980,height=560,resizable=no,toolbar=no,menubar=no');
}

function openNewWindowGr() 
{
	MM_openBrWindow('http://www.dolcemunich.com/webview/default-gr.asp','popup','width=980,height=560,resizable=no,toolbar=no,menubar=no');
}	
