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];}}
}

$(document).ready(function(){
   
 
    //used in press page
   // $("#accordion").accordion({
//		fillSpace: true,
//        autoHeight:true
//	});
 
   // fnSliderInitiation();
   fnVerticalSliderInitiation();
    //fnResizeSpacers();
    fnResizeBackground();
    fnOrnamentWidths();
   
    fnApplyMozillaStyle();
    fnResizeNav();
    //$(window).resize(fnResizeSpacers);
     $(window).resize(fnResizeNav);   
    $(window).resize(fnResizeBackground);
    
   
});

function fnResizeNav()
{
    
  
    winHeight=$(window).height();

        if(winHeight<800)
        {
           //winHeight=620;
           winHeight=800;
        }
      
        NavHieghtOrg=$("#divLeftContainer").height();        
        $("#divLeftContainer").height(winHeight);
    
        paddding=0;
        NavContHeight=$("#divNavContainer").height()+(winHeight- NavHieghtOrg)-paddding;
        $("#divNavContainer").height(NavContHeight);
        
        spacerheight=$("#spacermenu").height()+(winHeight- NavHieghtOrg)-paddding;
        $("#spacermenu").height(spacerheight);
        $("#spacermenu_contact").height(spacerheight-5);
        $("#spacermenu_bridal").height(spacerheight-5);
        

        //fnResizeSpacers();                
                       
      
     
}

function fnApplyMozillaStyle()
{
    
    jQuery.each(jQuery.browser, function(i, val) {
     
       if(i=="mozilla" )
       {
       
         $("li").css("margin-top","-5px");
         $("#divRightContainer #spacermenu").height($("#spacermenu").height()-5);
       }
      
     });
}

function fnSliderInitiation()
{
    
    
    $('#galleryslider').loopedSlider({
    	   containerClick: false,
            addPaginationExternal:true,
            externalPagingClass:".divPagingCell_"
            
            });
            
    //$('#newsrecentslider').loopedSlider({
//    	   containerClick: true,
//            addPaginationExternal:true,
//            externalPagingClass:".divPagingCell_recent"
//            });
//    $('#newsarchiveslider').loopedSlider({
//    	   containerClick: true,
//            addPaginationExternal:true,
//            externalPagingClass:".divPagingCell_archive"
//            });
        

}



function fnVerticalSliderInitiation()
{
 
$(function() {
   
	$(".newsticker-jcarousellite").jCarouselLite({
		vertical: true,
		hoverPause:false,
		visible: 1,
     
	    btnNext: ".next",
        btnPrev: ".prev",
		speed:1000
      
	});
});

}
function fnResizeBackground()
{
    ratio=1;
    
    intOrgWidth=1772;
    intOrgHeight=1329;
    
    docheight=$(document).height();
    whRation=intOrgWidth/intOrgHeight;
    
    intwinHeight=$(window).height();
    intwinWidth=$(window).width();
    ratio=intwinWidth/intOrgWidth;
    intwidth=intOrgWidth*ratio;
    intheight=intOrgHeight*ratio;
    
  
    if(intheight<intwinHeight)
    {
        
        ratio=intwinHeight/intOrgHeight;
        intwidth=intOrgWidth*ratio;
        intheight=intOrgHeight*ratio;
    }
    
    $("#bgimg").height(intheight);
    $("#bgimg").width(intwidth);
     $("#bgimg").css("position","fixed");
}
function fnOrnamentWidths()
{
    
        $(".ornamentcontainer").each(function()
        {
            indreduce=0;
            intMainwidth=$(this).width();
            intOrnamentwidth=$(this).find('.ornament').width()+$(this).find('.ornamentright').width()+$(this).find('.ornamentleft').width();
            
            intremainwidht=intMainwidth-intOrnamentwidth;
            intleftwidth=intremainwidht/2;
            intrightwidth=intleftwidth;
            
            $(this).find('.leftornament').width(intleftwidth-indreduce);
            
            $(this).find('.rightornament').width(intrightwidth-indreduce);
        }
        );
        
}

function fnResizeSpacers()
{
 //   spaceheight=$("#divNavContainer #spacermenu").height();
//    menuheight=$("#divNavContainer #divmenu").height();
//    logoheight=$("#divlogo").height();
    documentheight=$(window).height();
    documentwidth=$(window).width();
    

      // for the white overlay
      
    $("#divMainContainer").height(documentheight);
   
      //  $("#divMainContainer").width(documentwidth);
    
       
    
  //  if(documentheight>800)
//        documentheight=830;
//    bottmepadding=30;
//    menulogopadding=20;
//  
//    spaceheight=documentheight-menuheight-menulogopadding-logoheight-bottmepadding;
//    containerheight=menuheight+spaceheight;

    
    
   // $("#divNavContainer").height(containerheight);
//    $("#divNavContainer #spacermenu").height(spaceheight);
    
   
    
    topmargin=30;
    galleryheight=$("#divNavContainer").height()-topmargin;
    pressgallerheight=galleryheight;
     if(galleryheight<425)
     {
        galleryheight=425;
     }
        //for gallery
        gallerycontentheight=$("#gallerycontainer .gallery").height();
        //  gallerycontentheight=$("#gallery").height();
        $("#gallerycontainer").height(galleryheight);
        spacerheightgallery=galleryheight-gallerycontentheight;
        $("#gallerycontainer #galleryspacer").height(spacerheightgallery);
    
    

    if(pressgallerheight<500)
        pressgallerheight=500;
    
   //for press
    pressgallerycontentheight=$("#press").height();
    gallerycontentheight=$("#pressgallerycontainer .press_recent").height();
//   
    if(gallerycontentheight==0)
     gallerycontentheight=$("#pressgallerycontainer .press_archive").height();
   
    $("#pressgallerycontainer").height(pressgallerheight+40);
    spacerheightgallery=pressgallerheight-gallerycontentheight-20;
     
    
     $("#pressgallerycontainer #galleryspacer").height(spacerheightgallery);
   
  
}

/*------------------gallery and press-----------------------------*/
function fnLoadNew(news,strpage,intpage,item)
{
    
    strContainer="container";   
    if(strpage=='gallery')
        page="ajaxgallerylist.php";
    if(strpage=='press')
    {
        page="ajaxpressgallerylist.php";
        if(news=="archive")
            strContainer=strContainer+"_"+news;
        else
            strContainer=strContainer+"_"+news;
    }
    $.ajax({
            type: 'GET',
            url: 'pages/'+page+'?pageno='+intpage+'&news='+news,
            dataType: 'html',
            
            success: function(html, textStatus) 
                    {
                        fnMentainPagingImg(item);
                        $('#'+strContainer).html(html);
                        tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
                      
                    },
            
            error: function(xhr, textStatus, errorThrown) 
                    {
                        alert('An error occurred! ' + ( errorThrown ? errorThrown : xhr.status ));
                    }
            });
           
}


function fnMentainPagingImg(item)
{
     $(item).parent().parent().find("img").each(function(){
       
        $(this).attr("src","http://conniesimonetti.com/gui/paging.png");
        
    });
    $(item).find("img").attr("src","http://conniesimonetti.com/gui/pagingactive.png");

}



//function fnLoadNew(news,strpage,intpage,item)
//{
//    
//    $("#"+strpage+news+"_"+intpage).siblings().fadeOut(1500,function(){
//    $("#"+strpage+news+"_"+intpage).fadeIn(2000);    
//    });
//    
//}
