jQuery(document).ready(function(){
	randomBG();
	genDropMenu();
	
	classifiedImagesOnBlog();
});


function classifiedImagesOnBlog(){
	jQuery('#blogContent .oneBlog .content img').addClass('mobileFriendly');
}


function genDropMenu(){
	jQuery('#header ul.navigation.right li a').each(function(){
		var href = jQuery(this).attr('href');
		var text = jQuery(this).text();
		var tmp  = '<option value="'+href+'">'+text+'</option>';
		jQuery('#header select.navReplacer.right').append(tmp);
	});
	jQuery('#fooMenu ul.navigation.left li a').each(function(){
		var href = jQuery(this).attr('href');
		var text = jQuery(this).text();
		var tmp  = '<option value="'+href+'">'+text+'</option>';
		jQuery('#fooMenu select.navReplacer.left').append(tmp);
	});
	
	jQuery('#portfolioHead select option').remove();
	jQuery('#portfolioHead .navigation span, #portfolioHead .navigation a').each(function(){
		var href = jQuery(this).attr('href');
		var text = jQuery(this).text();
		
		if(href==undefined){
			var tmp  = '<option selected="selected" value="">'+text+'</option>';
		}else{
			var tmp  = '<option value="'+href+'">'+text+'</option>';
		}
		//alert(tmp);
		jQuery('#portfolioHead select').append(tmp);
	});
	
	jQuery('select.navReplacer, #portfolioHead select').change(function(){
		var val = jQuery(this).val();
		window.location.href = val;
	});
}

function randomBG(){
	var rand = Math.floor(Math.random()*4)+1;
	jQuery('#header, #footer').removeClass('bg1');
	jQuery('#header, #footer').removeClass('bg2');
	jQuery('#header, #footer').removeClass('bg3');
	jQuery('#header, #footer').removeClass('bg4');
	jQuery('#header, #footer').addClass('bg'+rand);
}

// =================================================================================================================================================
// =================================================================================================================================================
// getPageSize()
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function trim(str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function validateTheEmail(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address;
   if(reg.test(address) == false) {
      return false;
   }else{
      return true;
   }
}

function validateTheURL(value) {
  var urlregex = new RegExp("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
  if(urlregex.test(value)){
    return true;
  }else{
    return false;
  }
}
