/* 
 * @Author: Claudiu MAILAT - claudiu.mailat@arobs.com
 * Project: WildFrog Studio - wordpress scrolling theme
 * Version: 1.0 
*/
$(document).ready(function(){
    // set scroll bar 
   $('#services #page-content, #work #page-content, #about #page-content, .page-child #primary #page-content, .single-portfolio #primary #page-content, .page-template-default #primary #page-content').tinyscrollbar(); 
    // set defaul link
    var pagelink = document.location.href.split("#");
    var bloglink = document.location.href.split("?");      
    if(pagelink[1] == null && bloglink[1] == null){
        document.location.href = document.location.href + '#home';
    }
    
    // Scrolling menu - set properties for menu items
    $("#menu-main-menu li a[href*=#], .contact-link[href*=#], .view-work-link[href*=#]").click(function(event){      
		$("#menu-main-menu li a").removeClass('active');
		$(this).addClass('active');
        //prevent the default action for the click event       
        if($('body').hasClass('home')){
           event.preventDefault();    
        }
//        }else{
//            event.preventDefault();            
//        }
        
        //get the full url 
        var full_url = this.href;

        //split the url by # and get the anchor target name
        var parts = full_url.split("#");                
        var trgt = parts[1];              

        //get the top offset of the target anchor
        var target_offset = $("#"+trgt).offset();                     
        var target_top = target_offset.top;

        //go to that anchor by setting the body scroll top to anchor top
        $('html, body').animate({scrollTop:target_top}, 2000);
    });
    // Portfolio Hover Effects 
    $("#portfolio-container .portfolio_content").hover(
        // on mouse over 
        function(e){
            $(this).find(".entry .item_title, .read_more").css({
                    display: 'block'
            });
        },
        // on mouse out
        function(e){
            $(this).find(".item_title, .read_more").css({
                    display: 'none'
            });
        }
    );
    
    
});

// change background position on scroll
$(window).scroll(function(){
    var x = $(this).scrollTop();
    // get scroll bottom
    var scrollBottom = $(document).height() - $(window).height() - $(window).scrollTop();
    // get window height
    var windowheight = $(window).height();
    // website logo position 
    if(x < 4600){ //|| windowheight < 680){
        $('#website-logo .logo').css({
            width : 290 + 'px',
            height :106 + 'px', 
            top : 40 + 'px',
            'z-index' : 999999999999,
            background: 'url(http://www.wildfrogstudio.com/WFSNewSite2011/wp-content/themes/wildfrog/images/small-logo.png) no-repeat left top',
            'margin-left' : 0 + 'px',
            display: 'block'
        });
    }else{
         $('#website-logo .logo').css({
            width : 478 + 'px',
            height : 164 + 'px',
            top : 154 + 'px',
            'z-index' : 999999999999,
            background: 'url(http://www.wildfrogstudio.com/WFSNewSite2011/wp-content/themes/wildfrog/images/website-logo.png) no-repeat left top',
            'margin-left' : 258 + 'px',
            display: 'none'
        });
    }
      
    // Home page 
    var position = 'center ' + parseInt(x/10) + 'px ,center ' + parseInt(x/55) + 'px';
    $('#home').css("background-position", position);
    $('#page-content #home').css("background-position", position);
    // Contact page 
    var contactposition = 'center ' + parseInt(250+x) + 'px';
    $('#contact').css("background-position", contactposition);
     // About page 
    var aboutposition = 'center ' + parseInt(x/4) + 'px ,center ' + parseInt(x/25) + 'px';
    $('#about').css("background-position", aboutposition);
    
    // Master Container Background
    // Get position for the big bubbles
    if(x > 3200){
        var bubblesattachment = 'fixed';
        var bubblesposition = ' center ' + parseInt(x/50) + 'px';
    }else{
        var bubblesattachment = 'scroll';
        var bubblesposition = 'center 3300px';
    }
    if(x < 4820){
          $('#master-container').css({
                        'background-attachment' :  'scroll, scroll, scroll, scroll, scroll, ' + bubblesattachment,
                        'background-position' : '0 bottom, center 4900px ,center 0, center 440px, center 2143px,' + bubblesposition
                    });
    }else{
         $('#master-container').css({
                        'background-attachment' :  'scroll, fixed, scroll, scroll, fixed, scroll',
                        'background-position' : '0 bottom, center 100px, center 2143px, center 440px,center 2143px, center 0'
                    });
    }

// Show Comments
$("#showmessage").click(function(e){
    e.preventDefault();   
               $("#comments").css("display", "block");
});

}) 



  // Contact Form 
  function clearText(field)
  {
    if (field.defaultValue == field.value) field.value = '';
  }
  function restoreText(field) {
	if (field.value == '') field.value = field.defaultValue;
  }
  // Style Check box
  // assuming all checkboxes are unchecked at first
 $("span[class='wpcf7-list-item']").addClass("unchecked");

$(".wpcf7-list-item").click(function(){

        if($(this).children("input").attr("checked")){
                // uncheck
                $(this).children("input").attr({checked: ""});
                $(this).removeClass("checked");
                $(this).addClass("unchecked");
        }else{
                // check
                $(this).children("input").attr({checked: "checked"});
                $(this).removeClass("unchecked");
                $(this).addClass("checked");
        }

        alert($(this).children("input").attr("checked"));
}); 

		$(function(){
                    $('.singlepostcontent').columnize({ columns: 2 });
                });
