// Responsive Script
//
//alert($('meta[name="viewport"]').attr('content'));
//$('meta[name="viewport"]').attr('content', 'width=980');
//alert($('meta[name="viewport"]').attr('content'));

(function($) {
	$.fn.innerPageHandler = function( options ) {
	
		if ( $(window).width() < 600 ) {

			$('#navlist2').slicknav({label: '',duration: 1000});
			$( '.slicknav_menu_text' ).css( 'float', 'left' );
			$( '.slicknav_menu_text' ).css( 'width', '160px' );
			
			$( '.slicknav_menu_search' ).css( 'float', 'right' );
			
			$( '.slicknav_menu_search_text' ).css( 'border', '0px' );
			$( '.slicknav_menu_search_text' ).css( 'font-size', '15px' );
			$( '.slicknav_menu_search_text' ).css( 'width', '66px' );
			$( '.slicknav_menu_search_text' ).css( 'margin', '0' );
			$( '.slicknav_menu_search_text' ).css( 'padding', '0' );
			$( '.slicknav_menu_search_text' ).css( 'margin-top', '-25px' );
			$( '.slicknav_menu_search_text' ).css( 'background-color', '#013378' );
			$( '.slicknav_menu_search_text' ).css( 'border-bottom', '1px solid #718DB3' );
			$( '.slicknav_menu_search_text' ).css( 'color', '#ffffff' );
			$( '.slicknav_menu_search_text' ).css( 'vertical-align', 'middle' );
			
			$( '.slicknav_menu_search_img' ).attr( 'src', 'm/mobile_search.png' );
			$( '.slicknav_menu_search_img' ).css( 'width', '35px' );
			$( '.slicknav_menu_search_img' ).css( 'height', '35px' );
			$( '.slicknav_menu_search_img' ).click( function() {
				window.location.href = 'http://www.ntu.edu.sg/Search/Pages/default.aspx?cx=009909668336905004361%3Arb4bobfbnps&cof=FORID%3A10&ie=UTF-8&q=' + $( '.slicknav_menu_search_text' ).val();
			});
							
			// Handle sidenav
			if ( $( '.sidenav' ).length > 0 && $('div.mobile-sidenav').length == 0)
			{
				$secondLevelNav = $( '<div class="mobile-layout-sidenav mobile-only" style="background-color:#234c8a;"><strong><a class="mtoggle" href="#" style="float:right;"><img src="m/mobile_more.png"/></a></strong></div>' );

				$secondLevelNav.append( '<br style="clear:both"/> ' );
										
				$secondLevelNavContent = $( '<div class="mobile-sidenav"></div>' );
				$secondLevelNavContent.append( $( '.sidenav' ).clone().removeClass('sidenav') );
				
				$secondLevelNav.append( $secondLevelNavContent );
				$secondLevelNav.insertAfter( '.slicknav_menu' );
				
				$( '.mobile-sidenav' ).hide();
				$( '.mtoggle' ).click(function() {
					$( '.mobile-sidenav' ).slideToggle(500);
				});
			}

			//NTU logo
			if ($('.header.mobile-only').length == 0) {
				$mobileHeader = $( '<div class="header mobile-only"></div><br style="clear:both"/>' );
				$mobileHeader.append($( '.header h1' ).clone());
				$mobileHeader.insertBefore( '.slicknav_menu' );	
			}

			//Social					
			if ($('.fsocial.mobile-only').length == 0) {
				$mobileSocial = $( '<div class="fsocial mobile-only"></div><br style="clear:both"/>' );
				$mobileSocial.append($( '.fsocial' ).clone().removeClass('fsocial'));
				$mobileSocial.insertBefore( '#fooSecond' );	
			}					
		}		
	}	
}(jQuery));