/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var content_width = 572; 
function showBody(){
    jQuery('#container_main > div').animate({
        opacity:1
    },200);
    jQuery('#ajax-contaner').animate({
        width:content_width
    },200,function(){jQuery(this).css('display','block');});
}
jQuery(document).ready(function() {
    jQuery('.scrollable, #ajax-contaner').height(jQuery(window).height());
    jQuery('.meta-like').live('click',function(){
        var currentLike=jQuery(this);
        if(jQuery(this).attr('href')!='#')
            jQuery.post(jQuery(this).attr('href'), function(response) {
                currentLike.parent().html('<a class="liked">'+response+'</a>');
            });
        return false;
    });
    jQuery('#ajax-contaner').animate({
                width:1				
            },200,function(){jQuery(this).css('display','none');});
    jQuery('.container_clicker').live('click',function(){
        if(jQuery('#ajax-contaner').width()<10){
            jQuery('#ajax-contaner').animate({
                width:content_width
            },200,function(){jQuery(this).css('display','block');});
            jQuery(this).removeClass('show_content');
            jQuery(this).addClass('hide_content');
        }else{
            jQuery('#ajax-contaner').animate({
                width:1
            },200,function(){jQuery(this).css('display','none');});
            jQuery(this).removeClass('hide_content');
            jQuery(this).addClass('show_content');
        }
        return false;
    });
    jQuery('#main-menu li a').live('click',function(){
            jQuery('.container_clicker').removeClass('show_content');
            jQuery('.container_clicker').addClass('hide_content');
    });
//IMAGE LOADER
});
function theme_scripts(){

    fix_ie_zindex();
    jQuery('.imgload').preloadImages({
        showSpeed: 2000,   // length of fade-in animation, 500 is default
        easing: 'easeOutQuad'   // optional easing, if you don't have any easing scripts - delete this option
    });
    jQuery("a[rel^='prettyPhoto']").prettyPhoto({
        deeplinking:false
    });
    jQuery("label.overlabel").overlabel();
    jQuery('.featured-works').jcarousel({
        easing: 'swing',
        animation: 200,
        scroll: 1
    });
    jQuery('#home-blog-post').jcarousel({
        vertical: true,
        easing: 'swing',
        animation: 200,
        scroll: 1
    });
    jQuery('.scrollable, #ajax-contaner').height(jQuery(window).height());
    jQuery('.scrollable').jScrollPane({
        dragMaxHeight:100,
        wheelSpeed:20,
        animateScroll: true
    });
    var jScrollPaneApi = jQuery( '.scrollable' ).data( 'jsp' );
    
    jScrollPaneApi.scrollToY( 400, false )
    jScrollPaneApi.scrollToY( 0, true );

    jQuery( window ).resize( function() {
        jQuery('.scrollable,, #ajax-contaner').height(jQuery(window).height());
        jScrollPaneApi.reinitialise();
        
    });
	
    //YOUTUBE VMODE FIX
    jQuery("iframe").each(function(){
        var ifr_source = jQuery(this).attr('src');
        var pos = ifr_source.indexOf("youtube.com");
        if(pos > -1) {
            var wmode = "?autohide=1&wmode=opaque";
            jQuery(this).attr('src',ifr_source+wmode);
        }
    });	

    // ENTRY IMAGE SLIDE
    jQuery('.entry-image-slide').each(function(index){
        jQuery(this).after('<ul class="jcycle-pager nav-item'+index+'">').cycle({
            pager:  '.jcycle-pager',
            fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
            easing: 'jswing',
            pause: true,
            autostop: false,
            pager:  '.nav-item'+index,
            pagerAnchorBuilder: function(idx, slide) {
                return '<li><a href="#">*</a></li>';
            }
        });
    });
    jQuery("#contactform").validate();

    jQuery("#commentform").validate();
    // GO TO TOP
    jQuery('.anchorLink').click(function() {
        jQuery( '.scrollable' ).data( 'jsp' ).scrollTo(0,0);
    });
    imgIconOverlay(jQuery);
};
function fix_ie_zindex(){
    if (jQuery.browser.msie) {
        var zIndexNumber = 400;        
        jQuery('#header div, .slider_area div').each(function() {
            jQuery(this).css('zIndex', zIndexNumber);
            zIndexNumber -= 10;
        });
    }
}
function imgIconOverlay($) {
    // This will select the items which should include the image overlays
    jQuery("div.hover-content").each(function(){
        var	ctnr = jQuery(this).find('a.item-preview');
        var cntrDiv=jQuery(this);
        // insert the overlay image
        ctnr.each(function(){
            if (jQuery(this).children('img')) {
                if (jQuery(this).hasClass('iconPlay')) {
                    jQuery(this).append(jQuery('<div class="imgOverlay"><div class="symbolPlay"></div></div>'));
                } else if  (jQuery(this).hasClass('iconDoc')) {
                    jQuery(this).append(jQuery('<div class="imgOverlay"><div class="symbolDoc"></div></div>'));
                } else if (ctnr.hasClass('iconZoom')){
                    jQuery(this).append(jQuery('<div class="imgOverlay"><div class="symbolZoom"></div></div></div>'));
                }
            }
        })
        var overImg = ctnr.children('.imgOverlay');
        // var hoverInfo = ctnr.parent.next();

        if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 6) {
        // IE sucks at fading PNG's with gradients so just use show hide

        } else {
            // make sure it's not visible to start
            overImg.css('opacity',0);

            cntrDiv.hoverIntent(
                function(){
                    overImg.animate({
                        'opacity':'1'
                    },200,'swing');
                /*jQuery(this).children(':last-child').animate({
                        'opacity':'1'
                    },200,'swing');*/
                //                    jQuery(this).children('.jcycle-pager').animate({
                //                        'opacity':'0'
                //                    },500,'swing');

                },		// mouseover
                function(){
                    overImg.animate({
                        'opacity':'0'
                    },200,'swing');
                /* jQuery(this).children(':last-child').animate({
                        'opacity':'0'
                    },200,'swing');*/
                //                    jQuery(this).children('.jcycle-pager').animate({
                //                        'opacity':'1'
                //                    },500,'swing');

                }		// mouseout
                );
        }
    });
}
jQuery.fn.overlabel = function() {
    this.each(function(index) {
        var label = jQuery(this);
        var field;
        var id = this.htmlFor || label.attr('for');
        if (id && (field = document.getElementById(id))) {
            var control = jQuery(field);
            label.addClass("overlabel-apply");
            if (field.value !== '') {
                label.css("display", "none");
            }
            control.focus(function () {
                label.css("display", "none");
            }).blur(function () {
                if (this.value === '') {
                    label.css("display", "block");
                }
            });
            label.click(function() {
                var label = jQuery(this);
                var field;
                var id = this.htmlFor || label.attr('for');
                if (id && (field = document.getElementById(id))) {
                    field.focus();
                }
            });
        }
    });
};

