// globals
var g_ajaxLoading = false;
var g_windowCurHeight = 0;
var m_contentHeight = -1;
var m_contentViewAll = false;
var m_contentDiff = 0;
var m_contentMinHeight = 120;
var m_contentViewHeight = 100;
var m_contentViewScrolling = false;
var m_resizeInt = 0;
var m_agent = navigator.userAgent.toLowerCase();
var m_version = parseFloat(m_agent.substr(m_agent.indexOf("msie")+5, 3));

// browser testing
var isIE=(m_agent.indexOf("msie")==-1)?false:true;
$(document).ready(function() {
	initWindow();
});
function initWindow(bAjax)
{
	try {
		ddaccordion.init({
			headerclass: "lv21", //Shared CSS class name of headers group
			headerclass2: "lv20", //non expandable header
			contentclass: "submenu2", //Shared CSS class name of contents group
			revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
			mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
			collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
			defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
			onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
			animatedefault: false, //Should contents open by default be animated into view?
			persiststate: false, //persist state of opened contents within browser session?
			toggleclass: ["", "perm"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
			togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
			animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
			oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
				//do nothing
			},
			onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
				//initScroller();
			}
		});
		
		ddaccordion.init({
			headerclass: "lv23", //Shared CSS class name of headers group
			headerclass2: "lv22", //non expandable header
			contentclass: "submenu2", //Shared CSS class name of contents group
			revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
			mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
			collapseprev: false, //Collapse previous content (so only one open at any time)? true/false
			defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
			onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
			animatedefault: false, //Should contents open by default be animated into view?
			persiststate: false, //persist state of opened contents within browser session?
			toggleclass: ["", "perm"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
			togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
			animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
			oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
				//do nothing
			},
			onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
				//initScroller();
			}
		});
	}catch(e) {}

				// IE Bug
				var szTmp = new String(window.location);
				var nPos = szTmp.lastIndexOf('/');
				if(nPos!=-1) {
					szTmp = szTmp.substr(0, nPos+1)
					$('#sidenav a').each(function() {
						var szParse = $(this).attr('href');
						szParse = szParse.replace(szTmp, '');
						$(this).attr('href', szParse);
					});
				}
				ddaccordion.init({
					headerclass: "lv1", //Shared CSS class name of headers group
					headerclass2: "lv0", //non expandable header
					contentclass: "submenu", //Shared CSS class name of contents group
					revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
					mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
					collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
					defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
					onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
					animatedefault: false, //Should contents open by default be animated into view?
					persiststate: false, //persist state of opened contents within browser session?
					toggleclass: ["", "perm"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
					togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
					animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
				  oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
						//do nothing
					},
					onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
						//initScroller();
					}
					
					
       });
	/*g_ajaxLoading = true;
	try{
		$.ajax({url: 'js/accordion/'+g_includeAccordion,
			type: 'GET',
			cache: false,
			dataType: 'text',
			timeout: 10000,
			error: function() {
				initWindow();
				g_ajaxLoading = false;
			},
			success: function(data){
				$('#sidenav').html('');
				$('#sidenav').append(data);
				// IE Bug
				var szTmp = new String(window.location);
				var nPos = szTmp.lastIndexOf('/');
				if(nPos!=-1) {
					szTmp = szTmp.substr(0, nPos+1)
					$('#sidenav a').each(function() {
						var szParse = $(this).attr('href');
						szParse = szParse.replace(szTmp, '');
						$(this).attr('href', szParse);
					});
				}
				ddaccordion.init({
					headerclass: "lv1", //Shared CSS class name of headers group
					headerclass2: "lv0", //non expandable header
					contentclass: "submenu", //Shared CSS class name of contents group
					revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
					mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
					collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
					defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
					onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
					animatedefault: false, //Should contents open by default be animated into view?
					persiststate: false, //persist state of opened contents within browser session?
					toggleclass: ["", "perm"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
					togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
					animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
					oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
						//do nothing
					},
					onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
						//initScroller();
					}
				});
				g_ajaxLoading = false;
			}
		});
	}catch(e) { }
	*/  
	try{
		// set mouseover effect
		$('img[rollover]').each(function(index){
			if($(this).parent().attr('href')==CLASSID) {
				$(this).attr('norollover', $(this).attr('src'));
				$(this).attr('src', $(this).attr('rollover'));
			} else {
				$(this).attr('norollover', $(this).attr('src'));
				$(this).hover(function () {
						$(this).attr('src', $(this).attr('rollover'));
					},
					function () {
						$(this).attr('src', $(this).attr('norollover'));
					}
				);
			}
		});
	}catch(e) {}
	
	try{
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animation_speed: 'normal', /* fast/slow/normal */
			slideshow: false, /* false OR interval time in ms */
			autoplay_slideshow: false, /* true/false */
			opacity: 0.35, /* Value between 0 and 1 */
			show_title: false, /* true/false */
			allow_resize: true, /* Resize the photos bigger than viewport. true/false */
			default_width: 500,
			default_height: 600,
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'pp_default', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
			horizontal_padding: 40, /* The padding on each side of the picture */
			hideflash: true, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
			wmode: 'opaque', /* Set the flash wmode attribute */
			autoplay: true, /* Automatically start videos: True/False */
			modal: false, /* If set to true, only the close button will close the window */
			deeplinking: true, /* Allow prettyPhoto to update the url to enable deeplinking. */
			overlay_gallery: false, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
			keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */
			changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
			callback: function(){}, /* Called when prettyPhoto is closed */
			ie6_fallback: true,
			markup: '<div class="pp_pic_holder"> \
						<div class="ppt">&nbsp;</div> \
						<div class="pp_top"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
						<div class="pp_content_container"> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_loaderIcon"></div> \
									<div class="pp_fade"> \
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
										<div class="pp_hoverContainer"> \
											<a class="pp_next" href="#">next</a> \
											<a class="pp_previous" href="#">previous</a> \
										</div> \
										<div id="pp_full_res"></div> \
										<div class="pp_details"> \
											<div class="pp_nav"> \
												<a href="#" class="pp_arrow_previous">Previous</a> \
												<p class="currentTextHolder">0/0</p> \
												<a href="#" class="pp_arrow_next">Next</a> \
											</div> \
											<p class="pp_description"></p> \
											{pp_social} \
											<a class="pp_close" href="#">Close</a> \
										</div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
						<div class="pp_bottom"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
					</div> \
					<div class="pp_overlay"></div>',
			gallery_markup: '<div class="pp_gallery"> \
								<a href="#" class="pp_arrow_previous">Previous</a> \
								<div> \
									<ul> \
										{gallery} \
									</ul> \
								</div> \
								<a href="#" class="pp_arrow_next">Next</a> \
							</div>',
			image_markup: '<img id="fullResImage" src="{path}" />',
			flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
			quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
			iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
			inline_markup: '<div class="pp_inline">{content}</div>',
			custom_markup: '',
			social_tools: false
		});
	}catch(e){}
	g_windowCurHeight = $(window).height();
	
}

function autoOpenMenu()
{   
    $('.submenu a.selected').removeClass('selected');
    var pathname = window.location.pathname;
    
    var vPos = pathname.indexOf('v/');
    pathname = pathname.substr( vPos, pathname.length-vPos);
    pathname = decodeURI(pathname);
    pathname = pathname.toLowerCase();

   if( pathname.substr(-3) == '-my' )
   {   
      pathname = pathname.substr(0, pathname.length-3);
   }
   else if( pathname.substr(-2) == '-c'  )
   {   
       pathname = pathname.substr(0, pathname.length-2); 
   }

    var submenu = $('.submenu');
    var menuheader = $('.lv1');

    for( var i=0; i< menuheader.length; i++)
    {
        var anchor = $('a[href="'+pathname+'"]', submenu[i]);
        
        if( anchor.length > 0)
        {  
           $('a.selected', submenu[i]).removeClass('selected');
           if( $(submenu[i]).css('display') =='none' )
           {
              if( $(menuheader[i]).hasClass('perm') == false )
                 $(menuheader[i]).trigger('evt_accordion');
           }
           $(anchor).addClass('selected'); 
           break;  
        }
    }
}

function autoOpenMenuArena()
{   

    var submenu = $('.submenu');
    var menuheader = $('.lv1');
    
    for( var i=0; i< menuheader.length; i++)
    {
        var anchor = $('a.selected', submenu[i]);
        
        if( anchor.length > 0)
        {  
           if( $(submenu[i]).css('display') =='none' )
           {
              if( $(menuheader[i]).hasClass('perm') == false )
                 $(menuheader[i]).trigger('evt_accordion');
           }
           break;  
        }
    }
}
function toggle( id )
{
   if( $('#'+id).css('display') == 'none' )
   {
       $('#'+id).slideDown()
   }
   else
   {
       $('#'+id).slideUp()
   }
}

