// JavaScript Document

	jQuery(function($){
		
		
		
	//farm device type
		 var deviceVar = $(".deviceType").text();
//set up for tablet and phone
		 if(deviceVar=="tablet"){
			var currentWidth = window.innerHeight;
			var orient = (currentWidth < 900) ? "landscape" : "portrait";
		 }
		 else if (deviceVar=="phone"){
			 var currentWidth = window.innerHeight;
			var orient = (currentWidth < 900) ? "landscape" : "portrait";
		 }
		
		
		
		//farm page name
		var url = window.location.pathname;
		var filename = url.substring(url.lastIndexOf('/')+1);
		//highlight current
		$(".mainMenu li a").each(function (i) {
        var pageUrl = $(this).attr('href');
		var pagename = pageUrl.substring(pageUrl.lastIndexOf('/')+1);
	
		if (pagename == filename) {
				$(this).removeClass("NeutraNormal");
				$(this).addClass("NeutraBold");
		}
      });
		//farm background image and link
		var background = $(".backgroundSource").text();
		var urlActual = $(".urlSource").text();
		
			//keep window aspect ratio
        //var Wheight = window.innerHeight;
        //var Wwidth = window.innerWidth;
        //window.resizeTo(Wheight*1.26,Wheight);
     //$(window).bind('resizeEnd', function() {
    		//var WheightCalc = $(window).height();
			//window.resizeTo((WheightCalc*1.26),WheightCalc);
		//});
 	
			//split tablet/phone call from desktop
			if (deviceVar=="desktop"){
			//Supersized background image
			
				$.supersized({
					
					slides  :  	[ {image : background, title : 'Reddy Made Design', url : urlActual} ],
					horizontal_center : 0,
					 vertical_center : 0,
				
					
					  new_window : 0,
					  min_width : 650,
					  min_height :650
					
					
				});
			}
			else{
				
				$.supersized({
					
					slides  :  	[ {image : background, title : 'Reddy Made Design', url : urlActual} ],
					horizontal_center : 0,
					 vertical_center : 0,
					  fit_always : 1,
					  new_window : 0
										
					
				});	
				
				
			}
				
	//move menus up idf window is less than 705
	var winHeight = $(window).height();	
	var winWidth = $(window).width();	
	var imageWidth = $("#supersized img").width();
	
		
		var marginCalcAnim = winHeight - 705;
	
		if (marginCalcAnim < 146 && marginCalcAnim > 0 && deviceVar!="tablet" && deviceVar!="phone"){
		$(".mainMenu").stop().animate({ "margin-top": marginCalcAnim }, { duration: 500, queue: false });
		$(".subMenu").stop().animate({ "margin-top": marginCalcAnim }, { duration: 500, queue: false });
		}
		else if (marginCalcAnim > 146 && deviceVar!="tablet" && deviceVar!="phone"){
		$(".mainMenu").stop().animate({ "margin-top": 146 }, { duration: 500, queue: false });
		$(".subMenu").stop().animate({ "margin-top": 146 }, { duration: 500, queue: false });		
		}
		else if (marginCalcAnim <= 0 && deviceVar!="tablet" && deviceVar!="phone"){
		$(".mainMenu").stop().animate({ "margin-top": 0 }, { duration: 500, queue: false });
		$(".subMenu").stop().animate({ "margin-top": 0 }, { duration: 500, queue: false });
		}
	    else if(deviceVar=="tablet" || deviceVar=="phone" ){
					$(".mainMenu").stop().animate({ "margin-top": 0 }, { duration: 500, queue: false });
					$(".subMenu").stop().animate({ "margin-top": 0 }, { duration: 500, queue: false });
		
					if (orient=="portrait"){
							if(deviceVar=="phone"){
							$(".colophon").css('bottom',400);	
							}
							else{
							$(".colophon").css('bottom',500);
							}
					}
					else{
						//$(".colophon").animate({ "bottom": 10 }, { duration: 100, queue: false });
						$(".colophon").css('bottom',10);
					}
			
		}
		
	
	//page center on load
		var t=setTimeout("centerPage()",750);
	//resize textbox on load
	var t=setTimeout("resizeTextBox()",1000);
	
	
	//fix ie 8 issue of resize
	var rv = -1; // Return value assumes failure.
	
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }	
  if (rv > -1 && rv < 9 ){
	api.options.fit_always=true;
  }
  
  
		
	$(window).resize(function() {
		//code to detect end of resize
		 if(this.resizeTO) clearTimeout(this.resizeTO);
    this.resizeTO = setTimeout(function() {
        $(this).trigger('resizeEnd');
    }, 500);
		
     //move menus etc.
		currentWidth = window.innerHeight;
		 if(deviceVar=="tablet"){
		orient = (currentWidth < 900) ? "landscape" : "portrait";
		 }
		 else if (deviceVar=="phone"){
			orient = (currentWidth < 900) ? "landscape" : "portrait";
		 }
		winHeight = $(window).height();
		var marginCalcAnim = winHeight - 705;
	
		if (marginCalcAnim < 146 && marginCalcAnim > 0 && deviceVar!="tablet" && deviceVar!="phone"   ){
		$(".mainMenu").stop().animate({ "margin-top": marginCalcAnim }, { duration: 500, queue: false });
		$(".subMenu").stop().animate({ "margin-top": marginCalcAnim }, { duration: 500, queue: false });
		}
		else if (marginCalcAnim > 146 && deviceVar!="tablet"  && deviceVar!="phone" ){
		$(".mainMenu").stop().animate({ "margin-top": 146 }, { duration: 500, queue: false });
		$(".subMenu").stop().animate({ "margin-top": 146 }, { duration: 500, queue: false });		
		}
		else if (marginCalcAnim <= 0 && deviceVar!="tablet"  && deviceVar!="phone" ){
		$(".mainMenu").stop().animate({ "margin-top": 0 }, { duration: 500, queue: false });
		$(".subMenu").stop().animate({ "margin-top": 0 }, { duration: 500, queue: false });
		}
		else if(deviceVar=="tablet" || deviceVar=="phone" ){
					$(".mainMenu").stop().animate({ "margin-top": 0 }, { duration: 500, queue: false });
					$(".subMenu").stop().animate({ "margin-top": 0 }, { duration: 500, queue: false });
					if (orient=="portrait"){
							if(deviceVar=="phone"){
							$(".colophon").css('bottom',400);	
							}
							else{
							$(".colophon").css('bottom',500);
							}
					}
					else{
						//$(".colophon").animate({ "bottom": 10 }, { duration: 100, queue: false });
							$(".colophon").css('bottom',10);
					}
			
		}
		
		
		centerPage();
		resizeTextBox();
		

	});	//end resize	

	
	
		
		 
	
	
	
	
				
 });//end doc ready
		    
			
			function centerPage(){
			
				/*var winWidthC = $(window).width();
				var imageWidthC = $("#supersized img").width();
				var marginC = (winWidthC - (232+imageWidthC))/2;
				$("#content").stop().animate({ "margin-left": (marginC) }, { duration: 500, queue: false });
				$("#supersized img").stop().animate({ "margin-left": (marginC+232)}, { duration: 500, queue: false });*/
				
			}
			
			function resizeTextBox(){
				//textbox resize
				var curwinWidth = $(window).width();
				var curimageWidth = $("#supersized img").width();
				var curwinHeigth = $(window).height();
				if ( curwinWidth < 1152 || curwinHeigth <950) {
					if (curimageWidth < 720){
						$("#textBox").stop().animate({ "width": (curimageWidth- 200), "top":100 }, { duration: 500, queue: false });
					}
					else{
						$("#textBox").stop().animate({ "width": curimageWidth - 200, "top":350  }, { duration: 500, queue: false });
					}
					
					
				}	
				
			}
			
			function modifyScreen(){
				
				
			}
				
		// Cufon font replacement
			 
			 Cufon.replace('.avenirReplace a', { hover: true, fontFamily: 'Avenir LT Std' });
			  Cufon.replace('.avenirReplaceBody', {  fontFamily: 'Avenir LT Std' });
		
			 Cufon.replace('.mainMenu li a.NeutraBold', { hover: false, fontFamily: 'Neutra Text TF Light' });
			 
			 Cufon.replace('.mainMenu li a.NeutraNormal', { hover: {
        fontFamily: 'Neutra Text TF Light'
    }, fontFamily: 'Neutra Text' }); 
			 
			
