/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function showBody(){
    jQuery('#container_main > div').animate({
	opacity:1
    },200);
}
jQuery(document).ready(function() {
    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;
    });
    //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
    });

    //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('body,html').animate({scrollTop:0},'slow');
    });
    imgIconOverlay(jQuery);
    newPostition=(jQuery('#header').css('background-position')+"").split(" ");
    var divh = document.getElementById('header').offsetHeight;
    jQuery(".slider_area").css("background-position",newPostition[0]+" -"+divh+"px");
    //var divh = document.getElementById('header').offsetHeight;
   // jQuery(".slider_area").css("background-position","<?php echo $posx;?>% -"+divh+"px");

};
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();
		}
	    });
	}
    });
};
