var site_url = "http://www.ural-k-s.ru/";
/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};


    function getSelText(){
           var txt = '';
           if (window.getSelection){
                   txt = window.getSelection();
           }else if (document.getSelection){
                   txt = document.getSelection();
           }else if (document.selection){
                   txt = document.selection.createRange().text;
           }
           return txt;
    }


$(document).ready(function() {
    
    //Комментарии
    //$("#comment").markItUp(mySettings);

    $("#suggestions").fadeOut(0);
    $("#inputString").keyup(function (){
        
        var string = $("#inputString");
        
        if ($(this).val().length > 3)
        {
            
            var timeout_id = setTimeout(function() {
                
                jQuery.post("/main/ajax_search.html", {"search_string" : $(string).val()},
                function(data){
                    if (data.result != false)
                    {
                        $("#suggestions_search").html(data.result).fadeIn(500);
                        $("#suggestions").fadeIn(500);
                        $(".search_name").css("display","inherit");
                        $("#search_string").val($(string).val());
                    }
                    else
                    {
                        $("#suggestions_search").html("<div id='search_no_results'>По результатам Вашего запроса ничего не было найдено.</div>").fadeIn(500);
                        $("#suggestions").fadeIn(500);
                        $(".search_name").css("display","inherit");
                        $("#search_string").val("");
                    }
                }, "json");
                
            }, 500)
            
        }
        else
        {
            $("#suggestions").css("display","none");
            $(".search_name").css("display","none");
        }
        
    });
    
  	 $("#inputString").blur(function(){
	 	$('#suggestions').fadeOut(300)
	 });
     
     
     var IE=!!top.execScript;
     
     if (!IE)
     {
         var admin = $("#admin");
         if ($.cookie("top") < 0)
         {
            $.cookie("top", 0);
         }
         admin.animate({"left" : $.cookie("left") + "px", "top" : $.cookie("top") + "px"}, 1000);
     
        $("#admin").draggable({ scroll: true,
                stop: function(e,ui) {
    				$.cookie("top", ui.position.top);
                    $.cookie("left", ui.position.left);
    			}
          });
     }
     else
     {
        $("#admin").draggable({ scroll: true});
     }
     

      
    $("input[type=submit]").button();
    
    $("#disable, #enable").click(function(){
        $("#loading").css("display", "inherit");
        jQuery.post("/ajax/disable_page.html", {"co_id": $(this).attr("co_id"), "set" : $(this).attr("id")},
        function(data){
            window.location.reload();
        }, "json");
    });
    
    $(document).keypress(function(eventObject){
        if (eventObject.which == 13)
        {
            //alert(getSelText());
        }
    });

    $("a[rel=group], a[rel=group1], a[rel=group2], a[rel=group3], a[rel=group4], a[rel=group5], a[rel=group6], .highslide").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Изображение ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
    
    
    $("#search input, #search_string").focus(function(){
        if ($(this).val() == "Поиск...") {
            $(this).val("");
        }
    }).blur(function(){;
        if ($(this).val() == "") {
            $(this).val("Поиск...");
        }
    });
    
    $("#auth_form_form").css("display","inherit").fadeOut(0);
    
    $("#auth_form_open").click(function(){
        $("#login_auth_invis").css("display","none");
        $("#auth_form").animate({"height":"289px"}, 500, function(){
            $("#auth_form_form").fadeIn(300);
        });
    });
    
    $('#content').click(function(){
        $("#auth_form").stop();
        $("#auth_form_form").fadeOut(100);
        $("#auth_form").animate({"height":"50px"}, 500, function(){
            $("#login_auth_invis").css("display","inherit");
        });
    });
    
    $("input:not(#search input)").focusin(function(){
        $(this).css({"backgroundColor":"#fff6ef"});
    });
    
    $("input:not(#search input)").focusout(function(){
        $(this).css({"backgroundColor":"white"});
    });
    
    $(".tbl tr:even td").css("background", "#f1f1f1");
    
    
    
   	var e = $(".scrollTop");
	var	speed = 500;
	
	e.click(function(){
		$("html:not(:animated)" +( !$.browser.opera ? ",body:not(:animated)" : "")).animate({ scrollTop: 0}, 500 );
		return false;
	});
	
	function show_scrollTop(){
		( $(window).scrollTop()>300 ) ? e.fadeIn(600) : e.hide();
	}
	$(window).scroll( function(){show_scrollTop()} ); show_scrollTop();
    
});


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// это кусок кода для определения того, включен ли флеш




// initialize global variables
var detectableWithVB = false;
var pluginFound = false;


function goURL(daURL) {
    // if the browser can do it, use replace to preserve back button
    if(javascriptVersion1_1) {
	window.location.replace(daURL);
    } else {
	window.location = daURL;
    }
    return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) ||
	(!pluginFound && !redirectIfFound)) ) {
	// go away
	goURL(redirectURL);
	return pluginFound;
    } else {
	// stay here and return result of plugin detection
	return pluginFound;
    }
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Director');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectQuickTimeActiveXControl();
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows


if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}




function flashOn(){
var res = false;
if(canDetectPlugins()) {
    //document.write('Плагины обнаружены - Урра!!');
	/*document.write('<b>Supports Shockwave for Director:</b> ' + detectDirector() + '<br>' +
		   '<b>Supports Shockwave Flash:</b> ' + detectFlash() + '<br>' +
		   '<b>Supports QuickTime:</b> ' + detectQuickTime() + '<br>' +
		   '<b>Supports RealPlayer:</b> ' + detectReal() + '<br>' +
		   '<b>Supports Windows Media Player:</b> ' + detectWindowsMedia());*/

		   if (detectFlash())
		   //document.write('/nФлеш включен');
			res = true;
		   //else
		   //document.write('/nФлеш вЫключен');
}
//else
//{
//	document.write('Плагины не обнаружены =(');
//}
return res;

}



