$(document).ready(function() {           
            
            var thisPage = window.location.pathname;
            if (thisPage == '/index.php') thisPage = '/index.php/home';
            
            //alert(thisPage);
            var thisLink = $("#first-nav a[href='"+thisPage+"']");
            thisLink.css({'color':'#00FF00'});
            var pointerWidth = $('#pointer').width();
            init_pointer();
            
            
            var resizeTimer = null;
            $(window).bind('resize', function() {
                if (resizeTimer) clearTimeout(resizeTimer);
                resizeTimer = setTimeout(init_pointer, 100);
            });

            $('#first-nav a ').mouseover(function(){         
                x = get_offset($(this));
                animate_pointer(x);
            });
            
            $('#first-nav a ').mouseout(function(){         
                x = get_offset(thisLink);
                animate_pointer(x);
                //alert('out');
            });

           function get_offset(elem){
                                    var o = elem.offset();
                                    var w = elem.width();
                                    //var w = 158; 
                                    var x = o.left + w/2 + pointerWidth/2;
                                    return x;               
           }
           function init_pointer(){
                var x = get_offset(thisLink);
                move_pointer(x);
                $('#pointer').show();               
           }
           function animate_pointer(x){
               $('#pointer').animate({"left": x+"px"} , {queue:false, duration:750});                
           };
           function move_pointer(x){
               $('#pointer').css({left:x});
               //$('#green-pointer').animate({"left": x+"px"} , {queue:false, duration:1000});                
           };    
           
            $('.theme-switcher').click(function(e){
                //e.preventDefault();
                

                var theme = $(this).text().toLowerCase();
                createCookie('theme', theme);
                //alert(theme);
                //var lastAddedElement = $('#theme').remove();
               //$('head').append('<link id = "theme" rel="stylesheet" href="/css/'+ theme +'.css" type="text/css" />');
               //$('body').css({'background-image' : '/css/'+theme+'.png'}); 
            });
            
            function createCookie(name,value,days) {
            if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
            }
            else var expires = "";
            document.cookie = name+"="+value+expires+"; path=/";
            }

            function readCookie(name) {
                var nameEQ = name + "=";
                var ca = document.cookie.split(';');
                for(var i=0;i < ca.length;i++) {
                    var c = ca[i];
                    while (c.charAt(0)==' ') c = c.substring(1,c.length);
                    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
                }
                return null;
            }

            function eraseCookie(name) {
                createCookie(name,"",-1);
            }

            $('.content-box').css({'-moz-border-radius':'15px','-webkit-border-radius':'15px','border-radius':'15px'});

            $('#contact-success').css({'-moz-border-radius':'15px','-webkit-border-radius':'15px','border-radius':'15px'});

            $('#contact-form').css({'-moz-border-radius':'15px','-webkit-border-radius':'15px','border-radius':'15px'});
          
        });