/*
	Kosmic Music JavaScript Document
	Author: Madhan Vijayakumar
	Company: Rising Solutions Inc	
*/
function myplaylist(x){
	(!window.win)? true : window.win.close();
	xh = (screen.height/2) - 230;
	xw = (screen.width/2) - 250;
	win = window.open(x,'','height=460,width=500,resizable=no,scrollbars=no,status=yes,location=no,menubar=no,titlebar=no');
	win.moveTo(xw,xh);
	win.focus();
}
function checkall(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      	if(theForm[z].type == 'checkbox' && theForm[z].name != 'check_all'){
		  theForm[z].checked = theElement.checked;
		}
     }
}

function checkall2(cbn,tid,frm){
		var d = document.forms[frm];
		var tbl  = document.getElementById(tid);
	    var rows = tbl.getElementsByTagName('tr');
		if (cbn.checked){
			for (var row=1; row<rows.length; row++){
			     //rows[row].className = "list3";
				 if (d.productSerials[row-1]) d.productSerials[row-1].checked = true;
			}
		}
		else{
			for (var row=1; row<rows.length; row++){
			    if (d.productSerials[row-1]) d.productSerials[row-1].checked = false;
			}
		}
}

function wopen(x,w,h){
	(!window.win)? true : window.win.close();
	var wsrc, wx, wy;
	wx = (screen.width/2) - (w/2);
	wy = (screen.height/2) - (h/2);
	wsrc = "width=" + w + ",height=" + h + ",scrollbars=no,status=yes,location=no,menubar=no,titlebar=no";
	win = window.open(x,'',wsrc);
	win.moveTo(wx,wy);
	win.focus();
}
window.addEvent('domready', function(){
	// Categories Menu (Click)
	/*
	if($$('a.catgmenusub span').length > 0){
		$$('a.catgmenusub span').each(function(cmspan){
			cmspan.addEvent('mouseover', function(event){
				new Event(event).stop();
				var catg_part = cmspan.getParent('a');
				if(catg_part.getNext('div')){
					if(catg_part.getNext('div').getStyle('display') == 'none'){
						catg_part.addClass('catgmenusel');					
						catg_part.getNext('div').setStyle('display','');
					} else{
						catg_part.removeClass('catgmenusel');
						catg_part.getNext('div').setStyle('display','none');
					}
				}
			});
		});
	}
	// Categories Menu (Mouse Over)
	if($$('a.catgmenusub').length > 0){
		$$('a.catgmenusub').each(function(cmspan){
			cmspan.addEvent('mouseover', function(event){
				new Event(event).stop();
				var catg_part = cmspan;
				if(catg_part.getNext('div')){
					if(catg_part.getNext('div').getStyle('display') == 'none'){
						catg_part.addClass('catgmenusel');					
						catg_part.getNext('div').setStyle('display','');
					} else{
						catg_part.removeClass('catgmenusel');
						catg_part.getNext('div').setStyle('display','none');
					}
				}
			});
		});
	}*/
	new Accordion('span.atStart1', 'div.atStart1', {
		show: -1,
		opacity: false,
		onActive: function(toggler, element){
			toggler.addClass('browsemenuon');
		},
		onBackground: function(toggler, element){
			toggler.removeClass('browsemenuon');
			element.setStyle('height', element.offsetHeight);
			$$('div.atStart2').setStyle('height','0');
			$$('span.atStart2').removeClass('browsemenuon');
			$$('div.atStart3').setStyle('height','0');
			$$('span.atStart3').removeClass('browsemenuon');
		},
		alwaysHide: true
	}, $('browse'));
	new Accordion('span.atStart2', 'div.atStart2', {
		show: -1,
		opacity: false,
		onActive: function(toggler, element){
			toggler.addClass('browsemenuon');
			toggler.getParent().getParent().setStyle("height", "auto");
		},
		onBackground: function(toggler, element){
			toggler.removeClass('browsemenuon');
			element.setStyle('height', element.offsetHeight);
			$$('div.atStart3').setStyle('height','0');
			$$('span.atStart3').removeClass('browsemenuon');
		},
		alwaysHide: true
	}, $('browse'));
	new Accordion('span.atStart3', 'div.atStart3', {
		show: -1,
		opacity: false,
		onActive: function(toggler, element){
			toggler.addClass('browsemenuon');
			toggler.getParent().getParent().setStyle("height", "auto");
		},
		onBackground: function(toggler, element){
			toggler.removeClass('browsemenuon');
			element.setStyle('height', element.offsetHeight);
		},
		alwaysHide: true
	}, $('browse'));	
	//----------------------------------------------------------------------------------
	if($$('.ecard')[0]){
		if((document.location.href).match(/ecard/i) != null){
			$$('.ecard')[0].setStyle('font-weight','bold');
		}
	}
	if($$('.horoscope')[0]){
		if((document.location.href).match(/horoscope/i) != null){
			$$('.horoscope')[0].setStyle('font-weight','bold');
		}
	}
	if($$('.meditation')[0]){
		if((document.location.href).match(/meditation/i) != null){
			$$('.meditation')[0].setStyle('font-weight','bold');
		}
	}
	// Playlist
	if($('myplaylist')){
		if($$('#myplaylist li').length <= 3){
			$('playlist_dragarea').setStyle('display','none');
		} else{
			var playlist_steps = ($$('#myplaylist li').length-3);
			$('playlist_knob').setStyle('height', (105/(playlist_steps+1)));
			var playlist_scroll = new Fx.Scroll('myplaylist', {
				wait: false,
				duration: 500,
				transition: Fx.Transitions.Cubic.easeInOut
			});
			new Slider($('playlist_dragarea'), $('playlist_knob'), {
				steps: playlist_steps,
				mode: 'vertical',
				onChange: function(step){
					playlist_scroll.toElement($$('#myplaylist li')[step]);				
				}
			}).set(0);			
		}
	}
	// Top Lists
	if($$('#tl_menu li').length > 0){
		$$('#tl_menu li').each(function(tlli, liindex){
			tlli.addEvent('click', function(event){
				new Event(event).stop();
				$$('li.tl_active').removeClass('tl_active');
				new Fx.Scroll('tl_wrap', {
					wait: false,
					duration: 500,
					transition: Fx.Transitions.Cubic.easeInOut
				}).toElement($$('#tl_cont div')[liindex]);
				this.addClass('tl_active');
			});
		});
	}
	// Accordian
	var accordion = new Accordion('h3.atStart', 'div.atStart', {
		show: 0,
		opacity: false,
		onActive: function(toggler, element){
			toggler.addClass('accordon');
		},
		onBackground: function(toggler, element){
			toggler.removeClass('accordon');
		}
	}, $('accord'));
	// Featured Albums, Audio Books & Videos
	if($$('div.fav_album_container div').length > 0){
		$$('div.fav_album_container div').each(function(fav_div){
			fav_div.addEvent('mouseover', function(event){
				this.setStyle('background-position','center -156px');
			});
			fav_div.addEvent('mouseleave', function(event){
				this.setStyle('background-position','center 0px');
			});
		});
	}
	if($('fdalbums')){
		if($$('#fdalbums li').length <= 4){
			$('fddrag').setStyle('display','none');
			if($$('#fdalbums div').length < 5){
				var objs = $$('#fdalbums div').clone();
				var total_div = $$('#fdalbums div').length;
				$$('#fdalbums ul')[0].setProperty('id','oldUL');
				$$('#fdalbums ul')[0].setStyle('display','none');
				var newul = new Element('ul').injectInside($('fdalbums'));
				new Element('li', {
					'id': ('newli_0')
				}).injectInside(newul);
				for(x=0; x < total_div; x++){
					if(x > 0){
						new Element('li', {
							'id': ('newli_'+x)
						}).injectAfter(('newli_'+(x-1)));						
					} 
					$('newli_'+x).adopt(objs[x]);
				}
				$('fdalbums').setStyle('height','160px');				
				$$('#fdalbums div').setStyle('margin-top','0px');
				$('oldUL').empty();
			}
		} else{
			var fdalbums_steps = ($$('#fdalbums li').length-4);
			//$('fddrag_knob').setStyle('width', (460/(fdalbums_steps+1)));
			$('fddrag_knob').setStyle('width', '100px');
			var fdalbums_scroll = new Fx.Scroll('fdalbums', {
				wait: false,
				duration: 500,
				transition: Fx.Transitions.Cubic.easeInOut
			});
			var albums_slider = new Slider($('fddragdiv'), $('fddrag_knob'), {
				steps: fdalbums_steps,
				onChange: function(step){
					fdalbums_scroll.toElement($$('#fdalbums li')[step]);				
				}
			}).set(0);
			$$('#fddrag div.fav_knobleft')[0].addEvent('click', function(event){
				new Event(event).stop();
				if((albums_slider.step - 1) >= 0){
					albums_slider.set(albums_slider.step - 1);
				}
			});
			$$('#fddrag div.fav_knobright')[0].addEvent('click', function(event){
				new Event(event).stop();
				if((albums_slider.step + 1) <= fdalbums_steps){
					albums_slider.set(albums_slider.step + 1);
				}
			});
		}
	}
	// Featured Albums & Tips
	new Tips($$('.toolTipImg'), {
		maxTitleChars: 200,
		offsets: {'x': 8, 'y': 8}
	});
	// Audio Books
	if($('fdaudiobooks')){
		if($$('#fdaudiobooks li').length <= 4){
			$('fdaudiobooksdrag').setStyle('display','none');
		} else{
			var fdaudiobooks_steps = ($$('#fdaudiobooks li').length-4);
			//$('fdaudiobooksdrag_knob').setStyle('width', (460/(fdaudiobooks_steps+1)));
			$('fdaudiobooksdrag_knob').setStyle('width', '100px');
			var fdaudiobooks_scroll = new Fx.Scroll('fdaudiobooks', {
				wait: false,
				duration: 500,
				transition: Fx.Transitions.Cubic.easeInOut
			});
			var audiobooks_slider = new Slider($('fdaudiobooksdragdiv'), $('fdaudiobooksdrag_knob'), {
				steps: fdaudiobooks_steps,
				onChange: function(step){
					fdaudiobooks_scroll.toElement($$('#fdaudiobooks li')[step]);				
				}
			}).set(0);
			$$('#fdaudiobooksdrag div.fav_knobleft')[0].addEvent('click', function(event){
				new Event(event).stop();
				if((audiobooks_slider.step - 1) >= 0){
					audiobooks_slider.set(audiobooks_slider.step - 1);
				}
			});
			$$('#fdaudiobooksdrag div.fav_knobright')[0].addEvent('click', function(event){
				new Event(event).stop();
				if((audiobooks_slider.step + 1) <= fdaudiobooks_steps){
					audiobooks_slider.set(audiobooks_slider.step + 1);
				}
			});
		}
	}
	// Videos
	if($('fdvideos')){
		if($$('#fdvideos li').length <= 4){
			$('fdvideosdrag').setStyle('display','none');
		} else{
			var fdvideos_steps = ($$('#fdvideos li').length-4);
			//$('fdvideosdrag_knob').setStyle('width', (460/(fdvideos_steps+1)));
			$('fdvideosdrag_knob').setStyle('width', '100px');
			var fdvideos_scroll = new Fx.Scroll('fdvideos', {
				wait: false,
				duration: 500,
				transition: Fx.Transitions.Cubic.easeInOut
			});
			var fdvideo_slider = new Slider($('fdvideosdragdiv'), $('fdvideosdrag_knob'), {
				steps: fdvideos_steps,
				onChange: function(step){
					fdvideos_scroll.toElement($$('#fdvideos li')[step]);				
				}
			}).set(0);
			$$('#fdvideosdrag div.fav_knobleft')[0].addEvent('click', function(event){
				new Event(event).stop();
				if((fdvideo_slider.step - 1) >= 0){
					fdvideo_slider.set(fdvideo_slider.step - 1);
				}
			});
			$$('#fdvideosdrag div.fav_knobright')[0].addEvent('click', function(event){
				new Event(event).stop();
				if((fdvideo_slider.step + 1) <= fdvideos_steps){
					fdvideo_slider.set(fdvideo_slider.step + 1);
				}
			});			
		}
	}
	// Album List
	if($$('.album_list_wrap div.album_list').length > 0){
		$$('.album_list_wrap div.album_list').each(function(div){
			div.addEvent('mouseover',function(){
				div.setStyle('background-color','#F2EFEA');
			});
			div.addEvent('mouseout',function(){
				div.setStyle('background-color','');
			});
		});
	}
	// Track List
	if($$('.track_wrap div.track_list').length > 0){
		$$('.track_wrap div.track_list').each(function(div){
			div.addEvent('mouseover',function(){
				div.setStyle('background-color','#F2EFEA');
			});
			div.addEvent('mouseout',function(){
				div.setStyle('background-color','');
			});
		});
	}
	// Form BGG
	if($$('.form_wrap div.form_group').length > 0){
		$$('.form_wrap div.form_group').each(function(div){
			div.addEvent('mouseover',function(){
				div.setStyle('background-color','#F2EFEA');
			});
			div.addEvent('mouseout',function(){
				div.setStyle('background-color','');
			});
		});
	}
	// Button Color
	if($$('.button input').length > 0){
		$$('.button input').each(function(div){
			div.addEvent('mouseover',function(){
				div.setStyle('color','#FFCC00');
			});
			div.addEvent('mouseout',function(){
				div.setStyle('color','#FFFFFF');
			});
		});
	}
	// E-Card
	if($('ecard_img')){
		if($$('#ecard_img li').length <= 4){
			$('ecard_drag').setStyle('display','none');
		} else{
			var ecard_steps = ($$('#ecard_img li').length-4);
			//$('ecard_knob').setStyle('width', (460/(ecard_steps+1)));
			$('ecard_knob').setStyle('width', '100px');
			var ecard_scroll = new Fx.Scroll('ecard_img', {
				wait: false,
				duration: 500,
				transition: Fx.Transitions.Cubic.easeInOut
			});
			var ecard_slider = new Slider($('ecard_dragdiv'), $('ecard_knob'), {
				steps: ecard_steps,
				onChange: function(step){
					ecard_scroll.toElement($$('#ecard_img li')[step]);				
				}
			}).set(0);			
			$$('#ecard_drag div.fav_knobleft')[0].addEvent('click', function(event){
				new Event(event).stop();
				if((ecard_slider.step - 1) >= 0){
					ecard_slider.set(ecard_slider.step - 1);
				}
			});
			$$('#ecard_drag div.fav_knobright')[0].addEvent('click', function(event){
				new Event(event).stop();
				if((ecard_slider.step + 1) <= ecard_steps){
					ecard_slider.set(ecard_slider.step + 1);
				}
			});
		}
	}
	// Video List
	if($('video')){
		if($$('#video li').length <= 4){
			$('video_drag').setStyle('display','none');
		} else{			
			var video_steps = ($$('#video li').length-4);
			//$('video_knob').setStyle('width', (460/(video_steps+1)));
			$('video_knob').setStyle('width', '100px');
			var video_scroll = new Fx.Scroll('video', {
				wait: false,
				duration: 500,
				transition: Fx.Transitions.Cubic.easeInOut
			});
			var video_slider = new Slider($('video_dragdiv'), $('video_knob'), {
				steps: video_steps,
				onChange: function(step){
					video_scroll.toElement($$('#video li')[step]);				
				}
			}).set(0);
			$$('#video_drag div.fav_knobleft')[0].addEvent('click', function(event){
				new Event(event).stop();
				if((video_slider.step - 1) >= 0){
					video_slider.set(video_slider.step - 1);
				}
			});
			$$('#video_drag div.fav_knobright')[0].addEvent('click', function(event){
				new Event(event).stop();
				if((video_slider.step + 1) <= video_steps){
					video_slider.set(video_slider.step + 1);
				}
			});			
		}
	}
	if($$('div.track_list a.listen_sample').length > 0){
		$$('div.track_list a.listen_sample').each(function(alisten){
			alisten.addEvent('click',function(event){
				new Event(event).stop();
				if($('sample_player').getStyle('display') == 'block'){
					$('sample_player').setHTML('player');
					$('sample_player').setStyle('display','none');
				}			
				if(!alisten.hasClass('active_track')){
					$$('div.track_list a.listen_sample').removeClass('active_track');
					$('sample_player').setStyle('display','block');
					sampleMedia(alisten.getProperty('href'),alisten.getProperty('playerpath'));
					alisten.addClass('active_track');
				} else{
					alisten.removeClass('active_track');
				}
			});
		});
	}
	function sampleMedia(url,play_path){
		try{
			var contentsWidth = 490;
			var contentsHeight = 350;			
			if(url.match(/\.mp3/i)) {
				play_path = play_path + "/resources/swf/mp3player.swf";
				swfMP3 = new SWFObject(play_path,'mpl','450','20','7');
				swfMP3.addParam('allowscriptaccess','sameDomain');
				swfMP3.addVariable('file',url);
				swfMP3.addVariable('autostart','true');
				swfMP3.addVariable('repeat','false');
				swfMP3.addVariable('width','450');
				swfMP3.addVariable('height','20');
				swfMP3.write('sample_player');
			} else if(url.match(/\.flv/i)) {
				play_path = play_path + "/resources/swf/mediaplayer.swf?file="+url+"&autostart=true";
				swfFlv = new SWFObject(play_path, "flvvideo", "490", "350", "8", "#000000", "wmode", "transparent");
				swfFlv.addParam('allowfullscreen','true');
				swfFlv.addVariable('width','490');
				swfFlv.addVariable('height','350');
				swfFlv.write('sample_player');
			} else if (url.match(/\.mov/i)) {
				var movObj;
				movObj = '<object type="video/quicktime" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"';
				movObj += ' width="'+contentsWidth+'" height="'+contentsHeight+'" align="middle" >';
				movObj += '<param name="src" value="'+url+'" />';
				movObj += '<param name="autoplay" value="true" />';
				movObj += '<param name="controller" value="true" />';
				movObj += '<param name="scale" value="aspect" />';
				movObj += '<param name="bgcolor" value="black" />';
				movObj += '<embed src="'+url+'" controller="true" scale="aspect" autoplay="true" pluginspage="http://www.apple.com/quicktime/download/" align="middle" bgcolor="black" width="'+contentsWidth+'" height="'+contentsHeight+'"></embed>';
				movObj += '<object/>';
				$('sample_player').setHTML(movObj);
			} else if (url.match(/\.wmv/i) || url.match(/\.asx/i)) {
				var movObj;
				movObj = '<object  type="application/x-oleobject" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"';
				movObj += ' width="'+contentsWidth+'" height="'+contentsHeight+'">';
				movObj += '<param name="filename" value="'+url+'" />';
				movObj += '<param name="Showcontrols" value="true" />';
				movObj += '<param name="autoStart" value="true" />';
				movObj += '<embed type="application/x-mplayer2" src="'+url+'" Showcontrols="true" autoStart="true" width="'+contentsWidth+'" height="'+contentsHeight+'"></embed>';
				movObj += '<object/>';
				$('sample_player').setHTML(movObj);
			} else if (url.match(/\.rv/i) || url.match(/\.rm/i) || url.match(/\.rmvb/i)) {
				var movObj;
				movObj = '<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"';
				movObj += ' width="'+contentsWidth+'" height="'+contentsHeight+'">';
				movObj += '<param name="src" value="'+url+'" />';
				movObj += '<param name="controls" value="ImageWindow" />';
				movObj += '<param name="autostart" value="true" />';
				movObj += '<embed src="'+url+'" controls="ImageWindow" autostart="true" width="'+contentsWidth+'" height="'+contentsHeight+'"></embed>';
				movObj += '<object/>';
				$('sample_player').setHTML(movObj);
			} else if (url.match(/\.mpg/i) || url.match(/\.mpeg/i)) {
				var movObj;
				movObj = '<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"';
				movObj += ' width="'+contentsWidth+'" height="'+contentsHeight+'" id="videobox">';
				movObj += '<param name="Filename" value="'+url+'" />';
				movObj += '<param name="ShowControls" value="True" />';
				movObj += '<param name="AutoStart" value="True" />';
				movObj += '<param name="ShowStatusBar" value="False" />';
				movObj += '<param name="AutoRewind" value="True" />';
				movObj += '<embed src="'+url+'" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" showstatusbar="False" showdisplay="False" autorewind="True" showcontrols="True" autostart="True" width="'+contentsWidth+'" height="'+contentsHeight+'"></embed>';
				movObj += '<object/>';
				$('sample_player').setHTML(movObj);
			}
		}
		catch(e){
			//var movText = '<p class="warn">Your browser does not support the format</p>';
			$('sample_player').setHTML('player');
			$('sample_player').setStyle('display','none');
		}
	}
	
});