if($.browser.mozilla||$.browser.opera ){
    document.removeEventListener("DOMContentLoaded",jQuery.ready,false);
    document.addEventListener("DOMContentLoaded",function(){
        jQuery.ready()
    },false)
}
jQuery.event.remove( window, "load", jQuery.ready );
jQuery.event.add( window, "load", function(){
    jQuery.ready();
} );
jQuery.extend({
    includeStates:{},
    include:function(url,callback,dependency){
        if ( typeof callback!='function'&&!dependency){
            dependency = callback;
            callback = null;
        }
        url = url.replace('\n', '');
        jQuery.includeStates[url] = false;
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.onload = function () {
            jQuery.includeStates[url] = true;
            if ( callback )
                callback.call(script);
        };
        script.onreadystatechange = function () {
            if ( this.readyState != "complete" && this.readyState != "loaded" ) return;
            jQuery.includeStates[url] = true;
            if ( callback )
                callback.call(script);
        };
        script.src = url;
        if ( dependency ) {
            if ( dependency.constructor != Array )
                dependency = [dependency];
            setTimeout(function(){
                var valid = true;
                $.each(dependency, function(k, v){
                    if (! v() ) {
                        valid = false;
                        return false;
                    }
                })
                if ( valid ){
                    //document.getElementsByTagName('body')[0].appendChild(script);
                    jQuery('body').prepend(script);
                }
                else{
                    setTimeout(arguments.callee, 10);
                }
            }, 10);
        }
        else
            jQuery('body').prepend(script);
        return function(){
            return jQuery.includeStates[url];
        }
    },

    readyOld: jQuery.ready,
    ready: function () {
        if (jQuery.isReady) return;
        imReady = true;
        $.each(jQuery.includeStates, function(url, state) {
            if (! state)
                return imReady = false;
        });
        if (imReady) {
            jQuery.readyOld.apply(jQuery, arguments);
        } else {
            setTimeout(arguments.callee, 10);
        }
    }
});

/************** Include Javascript Files ***************/


/*********************** DOM READY --> Begin ****************************/

jQuery(document).ready(function($){

		jQuery.fn.live = function (types, data, fn) {
				jQuery(this.context).on(types,this.selector,data,fn);
				return this;
				};
	
	/* ---------------------------------------------------- */
    /*	Main Navigation
	/* ---------------------------------------------------- */

    (function() {

        var	arrowimages = {
            down: 'downarrowclass',
            right: 'rightarrowclass'
        };
        var $mainNav = $('.navigation').find('ul');
        var $submenu = $mainNav.find("ul").parent();
		
		$submenu.find('> a').addClass('child');

        $submenu.each(function (i) {
            var $curobj = $(this);
            this.istopheader = $curobj.parents("ul").length == 1 ? true : false;
            $curobj.children("a").append('<span class="' + (this.istopheader ? arrowimages.down : arrowimages.right) +'"></span>');
        });

        $mainNav.on('mouseenter', 'li', function() {
            var $this    = $(this),
            $subMenu = $this.children('ul');
            if($subMenu.length) $this.addClass('hover');
            $subMenu.hide().stop(true, true).show(200);
        }).on('mouseleave', 'li', function() {
            $(this).removeClass('hover').children('ul').stop(true, true).fadeOut(50);
        });

    })();

    /* end Main Navigation */
	
	 /* ---------------------------------------------------- */
    /*	Platform Menu
	/* ---------------------------------------------------- */

    (function() {

        var	arrowimages = {
            down: 'downarrowclass',
            right: 'rightarrowclass'
        };
        var $mainNav = $('.platform-menu').find('ul');
        var $submenu = $mainNav.find("ul").parent();
		
		$submenu.find('> a').addClass('child');

        $submenu.each(function (i) {
            var $curobj = $(this);
            this.istopheader = $curobj.parents("ul").length == 1 ? true : false;
            $curobj.children("a").append('<span class="' + (this.istopheader ? arrowimages.down : arrowimages.right) +'"></span>');
        });

        $mainNav.on('mouseenter', 'li', function() {
            var $this    = $(this),
            $subMenu = $this.children('ul');
            if($subMenu.length) $this.addClass('hover');
            $subMenu.hide().stop(true, true).show(200);
        }).on('mouseleave', 'li', function() {
            $(this).removeClass('hover').children('ul').stop(true, true).fadeOut(50);
        });

    })();

    /* end Platform Menu*/
	
	


    /* Query data-rel to rel --> Begin */
    if ($("a[data-rel]").length) {
        $('a[data-rel]').each(function() {
            $(this).attr('rel', $(this).data('rel'));
        });
    }	
    /* Query data-rel to rel --> End */	


	/* Custom --> Begin */

	(function() {
		
		var el = $('.head-title h3');
		
		el.each(function(){
			
			var myText = "", el, aStr, first;
				el = $(this);
				aStr = el.text().split(" ");
				first = aStr.shift();

				myText += "<span>" + first + " " + "</span>" + aStr.join(" ");
				   
			   el.html(myText);			
			
		});

	})();

	/* Custom --> End */	
	
	
	/* Notifications --> Begin */
	
	function handler(e) {
		var $target = $(e.target);
		if($target.is('.close-box')) {
			var $box = $target.parent();
			$box.animate({opacity: '0'}, 500, function() {
				$(this).slideUp(500, function() {
					$(this).remove();
				});
			});	
		}
	}

	$('.success, .info, .warning, .error').append('<span class="close-box">&times;</span>').click(handler);

	/* Notifications --> End */
	
  
    /* Twitter--> Begin */
    if($('#jstwitter').length) {
        JQTWEET.loadTweets();
    }
    /* Twitter--> End */


    /* Scrollpane --> Begin */
    if($('#scroll-pane').length) {
        $('#scroll-pane').jScrollPane({
            showArrows: true
        });
    }
    /* Scrollpane --> End */	


    /* Ui --> Begin */
    $(function() {
        $(".scroller_wrap").each(function() {
            slider_init(this);
        })
    });

    function slider_init(obj) {
        //scrollpane parts
        var scrollPane = $(obj),
        scrollContent = $(".scroller_block ul", obj);

        //build slider
        var scrollbar = $(".scroller_slider_bar", obj).slider({
            slide: function( event, ui ) {
                slide(ui.value, scrollPane, scrollContent)
            }
        });
		
        var handle = $('.ui-slider-handle', obj);
		
        var handleLeft = parseInt(handle.css('left'));
		
        var prev = $('.scroller_slider_prev', obj);
        var next = $('.scroller_slider_next', obj);
		
		var handle = $(".ui-slider-handle", obj);

        var handleSize = handle.width();
		
        //append icon to handle
        var handleHelper = scrollbar.find(".ui-slider-handle", obj)
		
        .css({
            width: handleSize,
            "margin-left": '-30px'
        })
        .wrap( "<div class='ui-handle-helper-parent'></div>" ).parent()
        .width('').width( scrollbar.width() - handleSize);
		

        //change overflow to hidden now that slider handles the scrolling
        scrollPane.css( "overflow", "hidden" );

        $(".scroller_slider_prev, .scroller_slider_next", obj).mousedown(function() {
            var delta = $(this).hasClass('scroller_slider_prev') ? -10 : 10
            scrollbar.slider("value", scrollbar.slider("value") + delta);
            slide(scrollbar.slider("value"), scrollPane, scrollContent);
			scrollbar.slider("value") == 0 ? prev.addClass("disabled") : prev.removeClass("disabled");
			scrollbar.slider("value") == 100 ? next.addClass("disabled") : next.removeClass("disabled");
        });
		
        $(".scroller_slider_prev, .scroller_slider_next").click(function() {
            return false;
        });

        scrollPane.mousewheel(function(e, delta) {
			
			e.preventDefault();
			
            var delta = delta > 0 ? 10 : -10;
			
            scrollbar.slider("value", scrollbar.slider("value") + delta);
            slide(scrollbar.slider("value"), scrollPane, scrollContent);
			
			scrollbar.slider("value") == 0 ? prev.addClass("disabled") : prev.removeClass("disabled");
			scrollbar.slider("value") == 100 ? next.addClass("disabled") : next.removeClass("disabled");
			
        });
    }

    function slide(val, scrollPane, scrollContent) {
        if ( scrollContent.width() > scrollPane.width() ) {
            scrollContent.css("margin-left", Math.round(
                val / 100 * ( scrollPane.width() - scrollContent.width() )
                ) + "px");
        } else {
            scrollContent.css( "margin-left", 0 );
        }
    }

    /* Ui --> End */


    /* Pics --> Begin */	
    if (jQuery(".pics").length) {
        jQuery('.pics').cycle({ 	
            fx:     'scrollHorz', 
            timeout: 0, 
            next:   '.next',
            prev:   '.prev',
            easing: 'easeOutQuint'
        });
    }
    /* Pics --> End */


    /* Tables --> Begin */
    var $table = $('table.feature-table', this);
    $('table.feature-table thead tr th:first-child').addClass('leftR');
    $('table.feature-table thead tr th:last-child').addClass('rightR');
    $table.find('tbody tr:odd').addClass('odd');
    /* Tables --> End */


    /* Scroll to Top --> Begin */
    $('a[href=#top]').click(function(){
        $('html, body').animate({
            scrollTop:0
        }, 'slow');
        return false;
    });
    /* Scroll to Top --> End */


    /* Notifications --> Begin */
    function handler(event) {
        var $target = $(event.target);
        if($target.is('.close-box')) {
            var $box = $target.parent();
            $box.animate({
                opacity: '0'
            }, 500, function() {
                $(this).slideUp(500, function() {
                    $(this).remove();
                });
            });	
        }
    }
		
    $('.custom-box-wrap').append('<span class="close-box">&times;</span>').click(handler);
    /* Notifications --> End */


    /* To top --> Begin */
    $BackTop = $('#back-top');
    var animating = false;
    $(window).scroll(function () {
        if ($(this).scrollTop() > 100 && !animating) {
            $BackTop.fadeIn(1000);
        } else {
            $BackTop.fadeOut(1000);
        }
    });

    $('#back-top a').click(function () {
        $BackTop.fadeOut(400);
        animating = true;
        $('body,html').animate({
            scrollTop: 0
        }, 800, function() {
            animating = false;
        });
        return false;
    });
    /* To top --> End */


    /* Image wrapper --> Begin */
    function handle_image(img) {
        var $curtain = $('<span class="curtain">&nbsp</span>');
        img.after($curtain);        
    }
	
    $img_collection = $('.zoomer img, .zoom img');
    $img_collection.each(function() {
        handle_image($(this));
    });
    /* Image wrapper --> End */    
    
    
    if($('#login, #create').length) {
        jQuery('#login, #create').fancybox({
            'titlePosition'		: 'inside',
            'transitionIn'		: 'none',
            'transitionOut'		: 'none'
        });
    }

   

    /* Video loading Fancybox --> Begin */
    $(".video-icon .zoomer").click(function() {
        $.fancybox({
            'padding'		: 0,
            'autoScale'		: false,
            'transitionIn'	: 'none',
            'transitionOut'	: 'none',
            'title'			: this.title,
            'width'			: 640,
            'height'		: 385,
            'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'), 
            'type'			: 'swf',
            'swf'			: {
                'wmode'				: 'transparent',
                'allowfullscreen'	: 'true'
            }
        });
        return false;
    });
	
	    $(".video-icon-vimeo .zoomer").click(function() {
        $.fancybox({
            'padding'		: 0,
            'autoScale'		: false,
            'transitionIn'	: 'none',
            'transitionOut'	: 'none',
            'title'			: this.title,
            'width'			: 640,
            'height'		: 385,
            'href'			: this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'), 
            'type'			: 'swf',
            'swf'			: {
                'wmode'				: 'transparent',
                'allowfullscreen'	: 'true'
            }
        });
        return false;
    });
    /* Video loading fancybox --> End */
	
	
    /* Prepare loading fancybox --> Begin */
    if($('.zoomer').length) {
        jQuery('.zoomer').fancybox({
            'overlayShow'	: false,
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic'
			
        });
    }	
    /* Prepare loading fancybox --> End */


    /* Tabs --> Begin */
    var $tabs1 = $('.tabs1');
    var $tabs2 = $('.tabs2');
    var $tabs3 = $('.tabs3');
    var tabs1 = $('.tabs-1');
    var tabs2 = $('.tabs-2');
    var $tabsfoot = $('#tabs-footer');
	
    $.fn.tabs = function(link) {
        $(link).find("ul.tabs-nav li:first").addClass("active").show(); //Activate first tab
        $(link).find(".tabs-container .tab-content:first").show(); //Show first tab content
        //On Click Event
        $(link).find('ul.tabs-nav li').click(function() {

            $(link).find('ul.tabs-nav li').removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            link.find('.tab-content').hide(); //Hide all tab content

            var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
            $(activeTab).fadeIn('normal'); //Fade in the active ID content
            return false;
        });
    };
    $tabs1.tabs($tabs1);
    $tabs2.tabs($tabs2);
    $tabs3.tabs($tabs3);
    tabs1.tabs(tabs1);
    tabs2.tabs(tabs2);
    $tabsfoot.tabs($tabsfoot);
    /* Tabs --> End */


    /* Toggle --> Begin */
    if($('.toggle-container').length) {	
        $(".toggle-container").hide(); //Hide (Collapse) the toggle containers on load
        //Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
        $("b.trigger").click(function(){
            $(this).toggleClass("active").next().slideToggle("slow");
            return false; //Prevent the browser jump to the link anchor
        });
    }
    /* Toggle --> End */


    /* Gallery --> Begin */
    if($('#gallery').length) {
        var $filterType = $('#filter a');
        var $list = $('#gallery');
        $list.css('height', $(this).height()/2.5);
        var $data = $list.clone();
        $filterType.click(function(event) {
            if ($(this).attr('data-rel') == 'everyone') {
                var $sortedData = $data.find('li');
            } else {
                $sortedData = $data.find('.'+ $(this).attr('data-rel'));
            }
            $('#filter li').removeClass('active');
            $(this).parent('li').addClass('active');

            $list.quicksand($sortedData, {
                attribute: 'id',
                duration: 500,
                easing: 'easeInOutQuad',
                adjustHeight: 'auto',
                useScaling: 'true'
            }, function(){
                $('.image-grid li').removeClass('last'); 
                $('.image-grid li:nth-child(3n)').addClass('last');
                $(".video-icon .zoomer").click(function() {
                    $.fancybox({
                        'padding'		: 0,
                        'autoScale'		: false,
                        'transitionIn'	: 'none',
                        'transitionOut'	: 'none',
                        'title'			: this.title,
                        'width'			: 640,
                        'height'		: 385,
                        'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
                        'type'			: 'swf',
                        'swf'			: {
                            'wmode'				: 'transparent',
                            'allowfullscreen'	: 'true'
                        }
                    });
                    return false;
                });
            });
            return false;
        });	
    }

    /* Gallery --> End */

	/* Functions for comments --> Begin */
    
    if(parseInt(jQuery("[name=is_user_logged_in]").val(),10)){
        var comments=jQuery(".comment-reply-link");
        jQuery.each(comments, function(index, value) {
            jQuery(value).removeAttr("onclick");
            jQuery(value).live('click',function(){
                
                if(jQuery(value).parents(".comment-body").find(".add-comment").length>0){
                    return false;
                }
                
                var comment_id=jQuery(value).closest("li").attr("comment-id");
                var html=jQuery("#addcomments_template").html();
				console.log(html);
                html=html.replace(/__INDEX__/gi, comment_id);
                jQuery("#commentform .add-comment").hide(300);
                jQuery(value).parent().after(html);
                return false;
            });

        });

        jQuery(".reset").live('click',function(){
            var form=jQuery(this).closest(".add-comment");
            jQuery(form).hide(300,function(){
                jQuery(form).remove();
            });
        });

        jQuery(".reply").live('click',function(){
            jQuery(this).closest(".add-comment").hide(300,function(){
                var comment_parent=jQuery(this).closest(".add-comment").attr("id-reply");
                var comment_content=jQuery(this).parent().find("textarea").eq(0).val();
                if(!comment_content.length){
                    alert("Write text a little please!!");
                    jQuery(this).closest(".add-comment").show();
                    return false;
                }
                var data = {
                    action: "add_comment",
                    comment_parent: comment_parent,
                    comment_post_ID:jQuery("[name=current_post_id]").val(),
                    comment_content:comment_content
                };
                //send data to server
                jQuery.post(ajaxurl, data, function(response) {
                    window.location.href=jQuery("[name=current_post_url]").val()+"?new_comment="+response;
                });

            });
        });
    }


    /* Functions for comments --> End */

    var $player = $('audio');

    if($player.length) {
        $player.mediaelementplayer({
            audioWidth  : '100%',
            audioHeight : '34px',
            videoWidth  : '100%',
            videoHeight : '100%'
        });
    }
    
    

});/************** DOM READY --> End ***********************/


 
		/* Widget Contact Form --> Begin */

    function submit_widget_contact_form(form_object){
        jQuery(form_object).next(".contact_form_responce").find("ul").eq(0).html("");
        jQuery(form_object).next(".contact_form_responce").find("ul").eq(0).removeClass();

        var data = {
            action: "contact_form_request",
            values: jQuery(form_object).serialize()
        };
        //send data to server
        jQuery.post(ajaxurl, data, function(response) {
            response=jQuery.parseJSON(response);
            jQuery(form_object).find(".wrong_data").removeClass("wrong_data");
            if(response.is_errors){
                console.log(form_object);
                jQuery(".contact_form_responce").addClass("contact_form_responce_error");
                jQuery.each(response.info,function(input_name, input_label) {
                    jQuery(form_object).find("[name="+input_name+"]").eq(0).addClass("wrong_data");
                    jQuery(".contact_form_responce").find("ul").eq(0).append('<li>'+lang_enter_correctly+' "'+input_label+'"!</li>');
                });
            }else{
                jQuery(form_object).next(".contact_form_responce").find("ul").eq(0).addClass("contact_form_responce_succsess");
                if(response.info == 'succsess'){
                    jQuery(form_object).next(".contact_form_responce").find("ul").eq(0).append('<li>'+lang_sended_succsessfully+'!</li>');
                }

                if(response.info == 'server_fail'){
                    jQuery(form_object).next(".contact_form_responce").find("ul").eq(0).append('<li>'+lang_server_failed+'!</li>');
                }

                jQuery(form_object).find("[type=text],textarea").val("");

            }
            //*****
            update_capcha();
            jQuery(form_object).next(".contact_form_responce").show(300);
        });


        return false;
    }
		/* Widget Contact Form --> End */

		/* Update capcha --> Begin */
    function update_capcha(){
        if(jQuery("[name=capcha_image_frame]").length>0){
            window.frames["capcha_image_frame"].location.reload();
        }
        if(jQuery("[name=capcha_image_frame_widget]").length>0){
            window.frames["capcha_image_frame_widget"].location.reload();
        }
    }
		/* Update capcha --> End */
		
		/* Function getElementsByClass --> Begin */

    function getElementsByClass(searchClass,node,tag) {
        var classElements = new Array();
        if ( node == null )
            node = document;
        if ( tag == null )
            tag = '*';
        var els = node.getElementsByTagName(tag);
        var elsLen = els.length;
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        for (i = 0, j = 0; i < elsLen; i++) {
            if ( pattern.test(els[i].className) ) {
                classElements[j] = els[i];
                j++;
            }
        }
        return classElements;
    }

		/* Function getElementsByClass --> End */
		
		/* Function Google map --> Begin */

    function gmt_init_map(Lat,Lng, map_canvas_id, zoom, maptype,info,show_marker,show_popup,scrollwheel,custom_controls) {
        var latLng = new google.maps.LatLng(Lat, Lng);
        var homeLatLng = new google.maps.LatLng(Lat, Lng);
		var custom_controls='1';

        switch(maptype){
            case "SATELLITE":
                maptype=google.maps.MapTypeId.SATELLITE;
                break;

            case "HYBRID":
                maptype=google.maps.MapTypeId.HYBRID;
                break;

            case "TERRAIN":
                maptype=google.maps.MapTypeId.TERRAIN;
                break;

            default:
                maptype=google.maps.MapTypeId.ROADMAP;
                break;

        }

        scrollwheel=parseInt(scrollwheel,10);
        var map;
        if(custom_controls.length>0){
        
            var options=merge_objects_options({
                zoom: zoom,
                center: latLng,
                mapTypeId: maptype,
                scrollwheel: scrollwheel,
                disableDefaultUI: true
            },custom_controls);
        
            map = new google.maps.Map(document.getElementById(map_canvas_id), options);
        }else{
            map = new google.maps.Map(document.getElementById(map_canvas_id), {
                zoom: zoom,
                center: latLng,
                mapTypeId: maptype,
                scrollwheel: scrollwheel
            });
        }
   

        show_marker=parseInt(show_marker,10);
        if(show_marker){
            var marker = new MarkerWithLabel({
                position: homeLatLng,
                draggable: false,
                map: map
            });


            if(show_popup && info!=""){
                google.maps.event.addListener(marker, "click", function (e) {
                    iw.open(map, marker);
                });
                var iw = new google.maps.InfoWindow({
                    content: '<span>'+info+'</span>'
                });
            }
        }

    }
		/* Function Google map --> End */
		
    function merge_objects_options(obj1,obj2){
        var obj3 = {};
        for (var attrname in obj1) {
            obj3[attrname] = obj1[attrname];
        }
        for (var attrname in obj2) {
            obj3[attrname] = obj2[attrname];
        }
        return obj3;
    }

