var W3CDOM=(document.createElement&&document.getElementsByTagName);
function initFileUploads(){if(!W3CDOM)return;var fakeFileUpload=document.createElement('div');fakeFileUpload.className='fakefile';fakeFileUpload.appendChild(document.createElement('input'));var image=document.createElement('img');image.src='../pictures/site/upload.gif';fakeFileUpload.appendChild(image);
var x=document.getElementsByTagName('input');
for(var i=0;i<x.length;i++){if(x[i].type!='file')continue;
if(x[i].parentNode.className!='fileinputs')continue;
x[i].className='file hidden';var clone=fakeFileUpload.cloneNode(true);
x[i].parentNode.appendChild(clone);x[i].relatedElement=clone.getElementsByTagName('input')[0];
x[i].onchange=x[i].onmouseout=function(){this.relatedElement.value=this.value;}}} 

//alert();
if (typeof hs != "undefined") {
    hs.graphicsDir = '/js/highslide/graphics/';
    hs.align = 'center';
    hs.transitions = ['expand', 'crossfade'];
    hs.fadeInOut = true;
    hs.dimmingOpacity = 0.8;
    hs.outlineType = 'rounded-white';
    hs.captionEval = 'this.thumb.alt';
    hs.marginBottom = 105; // make room for the thumbstrip and the controls
    hs.numberPosition = 'caption';

    // Add the slideshow providing the controlbar and the thumbstrip
    hs.addSlideshow({
      //slideshowGroup: 'group1',
      interval: 5000,
      repeat: false,
      useControls: true,
      overlayOptions: {
        className: 'text-controls',
        position: 'bottom center',
        relativeTo: 'viewport',
        offsetY: -60
      },
      thumbstrip: {
        position: 'bottom center',
        mode: 'horizontal',
        relativeTo: 'viewport'
      }
    });
}
function MM_preloadImages()
{ 
  var d=document;
  if(d.images) 
  {
    if(!d.MM_p) 
      d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
    for(i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0)
      { 
        d.MM_p[j]=new Image; 
        d.MM_p[j++].src=a[i];
      }
  }
}
function loadPages(addr, div)
{
    if (div!='') {
        jQuery('#'+div).load('/content/ajax&div='+div+'&link='+escape(addr));
        return false;
    }
    return true;
}

/*
    searchToGet()
    written by Matthias Dailey
    Wednesday, September 7, 2009
*/
function searchToGet( uri ) {
/*
    Author: Matthias Dailey
    Purpose: to create an associative array from a URI with GET parameters
    Preconditions: uri is a valid URI, e.g., "http://www.x.com/?alsj=q"
    Postconditions: if a search string exists, this will return an associative array
        where the key is a string corresponding to the GET parameters. If no search 
        string is found, the function returns false.
*/
    
    if (uri.indexOf('?') == -1) {
        return 1; // no question mark, no search
    }
    
    // extract the search string
    var search = uri.substr( uri.lastIndexOf('?')+1 ); // after the '?' to the end of the line
    
    return search;
    
    // split into pairs for each kay/value combination
    var pairs = search.split('&');
    
    // split pairs into a sub-array of each key and value
    var temp = new Array();
    for (i=0; i<pairs.length; i++) {
        pairs[i] = pairs[i].split('=');
        temp[pairs[i][0]] = pairs[i][1];
    }
    
    return temp;
}

function sendData(form, pageId)
{
    var url = window.location + jQuery('#'+form).attr('action');
    var data = jQuery('#'+form).serialize();
    var get = '&pageId='+pageId+'&div='+form+'&'+searchToGet(url);
    
    jQuery.ajax({
        url: '/content/ajax'+get,
        data: data,
        type: 'POST',
        cache: false,
        success: function (response){
            jQuery('#div_'+form).html(response);
        }
    });
    
    //jQuery('#'+form).load('/content/ajax&div='+div+'&link='+escape(addr));
    return false;
}

function setborder(id,flag) 
{if(flag==1) 
{document.getElementById("img"+id).style.border="1px solid #ffc600";} 
else 
{document.getElementById("img"+id).style.border="1px solid #ffffff";}} 
function getBrowserInfo(){var t,v=undefined;if(window.opera)t='Opera';else if(document.all){t='IE';var nv=navigator.appVersion;var s=nv.indexOf('MSIE')+5;v=nv.substring(s,s+1);} 
else if(navigator.appName)t='Netscape';return{type:t,version:v};} 
function bookmark(a){var url=window.document.location;var title=window.document.title;var b=getBrowserInfo();if(b.type=='IE'&&7>b.version&&b.version>=4)window.external.AddFavorite(url,title);else if(b.type=='Opera'){a.href=url;a.rel="sidebar";a.title=url+','+title;return true;}
else if(b.type=="Netscape")window.sidebar.addPanel(title,url,"");else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");return false;}
function coords(e)
{var posx=0;var posy=0;if(!e) e=window.event;if(e.pageX||e.pageY){posx=e.pageX;posy=e.pageY;}
else if(e.clientX||e.clientY){posx=e.clientX+document.body.scrollLeft
+document.documentElement.scrollLeft;posy=e.clientY+document.body.scrollTop
+document.documentElement.scrollTop;}
return{x:posx+10,y:posy+10};}
jQuery(document).ready(function($){
	MM_preloadImages();
	$('.anonslist').mouseover(function(){
		$('#preview'+this.id).toggle(true);
	});
	$('.anonslist').mouseout(function(){
		$('#preview'+this.id).toggle(false);
	});
	
	$('.rel_name').mouseout(function(){$('#preview').toggle(false)});
	$('.rel_name').each(function(){
	$(this).mousemove(function(event){
		var crd=coords(event);
		var list=$('#tracklist'+this.id).html();
		if(list!=''){$('#preview').offset({left:crd.x,top:crd.y});
		$('#preview #img').html(list);
		$('#preview').toggle(true, 'rel_name').each(function(){$(this).mouseout( function(){$('#preview').toggle(false);} );});}});});});
function play_track(id,url,arj)
{var track="http://servag.rupsy.ru/track.php?arj="+arj+"&url="+url;track=escape(track);var div='<div class="fll"><object type="application/x-shockwave-flash"  allowscriptaccess="always" allowfullscreen="true" data="/js/mp3/releases/OriginalMusicPlayer.swf" width="225" height="90"><param name="movie" value="/js/mp3/releases/OriginalMusicPlayer.swf" /><param name="FlashVars" value="firstColor=99cc33&secondColor=99cc33&backColor=383838&fontSize=small&strokeColor=808080&mediaPath='+track+'&autoPlay=true" /></object>';$('.track').toggle(false);$('#track'+id).html(div);$('#track'+id).toggle();return false;}
function next(dir,cnt)
{var w=180;var offset=$('#ilist').offset();var left=80;var len=(-w)*(cnt)+left;var width=dir*w*1;var offs=offset.left+width;if(offs<len)return;if(offs>left)return;$("#ilist").animate({"left":"+="+width+"px"},"slow");}
function getClientWidth()
{return document.compatMode=='CSS1Compat'&&!window.opera?document.documentElement.clientWidth:document.body.clientWidth;}
function getClientHeight()
{return document.compatMode=='CSS1Compat'&&!window.opera?document.documentElement.clientHeight:document.body.clientHeight;}

function showTrackList(idx)
{
	var w=getClientWidth();
	var h=getClientHeight();
	$('#tracklist').css('top',(h/2-295/2));
	$('#tracklist').css('left',(w/2-526/2));
	$('#tracklist').toggle(true);
	$('#tracklist #track_id').val(idx);
	var list=$('#list'+idx).html();
	$('#tracklist #area').html('<textarea name="tracks" id="list" style="width:450px;height:200px;" >'+list+'</textarea>');
	tinyMCE.init({mode:"textareas",theme:"simple"});
}
function tsubmit(form)
{tinyMCE.triggerSave();var list=form.list.value;var params=$(form).serialize();var idx=$('#tracklist #track_id').val();$.post('/ajax.php',params,function(data){saved(idx,list);});return false;}
function saved(idx,list)
{$('#success').toggle(true);$('#list'+idx).html(list);setTimeout('hideRes()',3000);}
function hideRes()
{$('#success').fadeOut("slow");}


$(document).ready(function(){

	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$("ul.topnav li").hover(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		//$(this).find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		$(this).find("ul.subnav").show();


		//Following events are applied to the trigger (Hover events for the trigger)
		}, function(){
			$(this).find("ul.subnav").delay(100).toggle(true).slideUp(0); //When the mouse hovers out of the subnav, move it back up
			//$(this).find("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
		}).hover(function() { 
			    $(this).addClass("subhover"); //On hover over, add class "subhover"
		    }, function(){	//On Hover Out
			    $(this).removeClass("subhover"); //On hover out, remove class "subhover"
	        });

    $('a.cur').click(function(){return false;});
    //$('ul.subnav').corner("round 6px").parent().css('padding', '1px').corner("round 7px");
    
    $('.facebookLink a').click(function(){
        var page = window.location;
        window.open('http://www.facebook.com/sharer.php?u='+escape(page), 'facebook', 'menubar=0,resizable=0,width=600,height=400,top=200,left=200');
        return false;
    });
    
    $('.round').corner('4px');
    
    //*
    var blocks = ['rels', 'fotos', 'mixes', 'inform'];
    var cnt = 5;
    for (var id in blocks){
        var val = blocks[id];
        $.ajax({url: '/content/ajax&cnt='+cnt+'&div='+val, async:false, success: function(resp){
            //if (navigator.appName=='Microsoft Internet Explorer'){ alert(val+'  -'+resp); }
            $('#'+val).append(resp); 
        }});
        
        var parent = jQuery('#'+val).parent();
        for (var c=cnt-1; c>=0; c--){
            var actv = '';
            if (c==0) actv=' activ';
            jQuery('<a href="#" class="'+val+' pages'+actv+'" rel="'+val+'_'+c+'"><!----></a>').insertBefore(parent);
        }
        jQuery('<div class="clear"><!----></div>').insertBefore(parent);
    }
    jQuery('.pages').click(function(){
        var rel = jQuery(this).attr('rel');
        var data = rel.split('_');
        var height = parseInt(jQuery('#'+data[0]).children().height());
        if (navigator.appName!='Microsoft Internet Explorer'){
            //if (data[0]=='rels') height += 5*1;
        }
        height *= parseInt(data[1]);
        jQuery('#'+data[0]).animate({'top': '-'+height});
        jQuery('.'+data[0]+'.pages').removeClass('activ');
        jQuery(this).addClass('activ');
        return false;
    });
    //*/
});



function loadSWF(div, filename, height, width)
{
/*
    var attributes = {
      'bgcolor':'#2C2C2C',
      'scale':'noscale',  
      'wmode':'opaque'
    };
	swfobject.embedSWF(filename, div, width, height, "9.0.0", "", null, null, attributes);
*/

    var SWF = 
    '<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+width+'" height="'+height+'">'+
    '    <param name="movie" value="'+filename+'" />'+
    '    <param name="quality" value="high" />'+
    '    <param name="wmode" value="opaque" />'+
    '    <param name="swfversion" value="8.0.35.0" />'+

    '    <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->'+

    '    <param name="expressinstall" value="Scripts/expressInstall.swf" />'+
    '    <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->'+
    '    <!--[if !IE]>-->'+
    '    <object type="application/x-shockwave-flash" data="'+filename+'" width="'+width+'" height="'+height+'>'+
    '      <!--<![endif]-->'+
    '      <param name="quality" value="high" />'+
    '      <param name="wmode" value="opaque" />'+
    '      <param name="swfversion" value="8.0.35.0" />'+
    '      <param name="expressinstall" value="Scripts/expressInstall.swf" />'+

    '      <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->'+
    '      <div>'+
    '        <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>'+
    '        <p><noindex><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></noindex></p>'+
    '      </div>'+
    '      <!--[if !IE]>-->'+
    '    </object>'+
    '    <!--<![endif]-->'+

    '</object>';

    $('#'+div).html(SWF);

}

window.onresize = function(event) {
   jQuery('ul.topnav li').css('z-index', 1);
}
//

