// JavaScript Document



$(document).ready(function(){

    // init skin based on (1) url or (2) HTML5 local storage
    if(gup('skin') && gup('skin')!=''){
		setTheme(gup('skin'));
    } else if(localStorage.getItem('skin')){
		setTheme(localStorage.getItem('skin'));
    }

    // enable mouseover event on the top navigation 
    navigation(); 
	
});





function setTheme(theme){

    if(theme=='grungy'){
        $('body').css('background-image','url(/wp-content/themes/digital-intent/img/grungy-background.jpg)');
        $('div.container').css('background-color','#646464');
	$('div.footer').css('background-color','#646464');
        $('#theme-grungy').css('color','#666');
            $('#theme-classic').css('color','#5a9cff');    
            $('#theme-chic').css('color','#5a9cff');  

   } else if(theme=='chic'){
        $('body').css('background-image','url(/wp-content/themes/digital-intent/img/chic-background.jpg)');
        $('div.container').css('background-color','#858484');
	$('div.footer').css('background-color','#858484');
        $('#theme-chic').css('color','#666');
            $('#theme-classic').css('color','#5a9cff');    
            $('#theme-grungy').css('color','#5a9cff');  
  
    }  else {
    theme='classic';
        $('body').css('background-image','url(/wp-content/themes/digital-intent/img/background.jpg)');
        //$('#container').css('background-url','/wp-content/themes/digital-intent/img/bg_body.jpg');    
        $('div.container').css('background-color','#1e1e1e');
	$('div.footer').css('background-color','#1e1e1e');
        $('#theme-classic').css('color','#666');
            $('#theme-grungy').css('color','#5a9cff');    
            $('#theme-chic').css('color','#5a9cff');  
  
    } 

    // set cookie
	localStorage.setItem('skin', theme);
	
	$(window).scroll(function() {
		if($(this).scrollTop() != 0) {
			$('#toTop').fadeIn();	
		} else {
			$('#toTop').fadeOut();
		}
	});
 
	$('#toTop').click(function() {
		$('body,html').animate({scrollTop:0},800);
	});
	
	
} 

// function to get argument
function gup(name){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec(window.location.href);
  if( results == null )
    return "";
  else
    return results[1];
}

// enable mouseover event on the top navigation
function navigation(){
    $('#menu li').removeClass('hover');
    $('#menu li a')
        .css({ opacity: 1.0})
        .mouseover(function(){
            $(this).stop().animate(
                { opacity: 0.0 }
                , 300
            );
        })
        .mouseout(function(){
            $(this).stop().animate(
                { opacity: 1.0 }
                , 1000 
            );
        })
} 
