function show(obj,offset){
	obj.style.display = "block";
	obj.style.visibility = "visible";
	if(!document.all&&!document.layers&&!document.getElementById)
	return;
	
	//offset = 0;
	//offset = ((screen.availWidth - 980) / 2)+offset;
	obj.style.right = offset + "px";
}
function hide(obj){
	obj.style.display = "none";
}
function toggle(obj,offset){
	if(obj.style.display == "none")
	{
		show(obj,offset);
	}
	else{
		hide(obj);
	}
}
function toggleb(obja,obj){

			
	if(obj.style.display == "none")
	{
		obja.style.background = 'url(../images/minus_icon.gif) left no-repeat';
		show(obj,0);
		obja.className = 'ico withopenchild';
	}
	else{
		obja.style.background = 'url(../images/plus_icon.gif) left no-repeat';
		hide(obj);
		obja.className = 'ico withchild';
	}
}
function togglec(obj){

	if(typeof(obj) != 'undefined'){
		objs = document.getElementsByTagName('ul');
		cnt = objs.length;
		for(i=0;i<cnt;i++){
			str = objs[i].id;
			if(str.indexOf('pdiv_') >= 0){
				if(obj.id == str){
					show(obj,0);
				}
				else{
					hide(objs[i]);
				}
			}
		}	
	}
	else{
		//show all 2nd level categories;
		objs = document.getElementsByTagName('ul');
		cnt = objs.length;
		for(i=0;i<cnt;i++){
			str = objs[i].id;
			if(str.indexOf('pdiv_') >= 0){
				show(objs[i],0);
			}
		}
		
	}
	
//	
//	if(obj.style.display == "none")
//	{
//		show(obj,offset);
//	}
//	else{
//		hide(obj);
//	}
}
function bookmark(title,url){
  if (window.sidebar)
  {
    window.sidebar.addPanel(title, url, '');
  }
  else if (window.external)
  {
    window.external.AddFavorite(url, title);
  }
  else
  {
    alert('sorry, can not add to bookmark.');
  }

}
function slideShow() {
    var $active = $('#hero_media A.active');
    var $activetxt = $('#hero_media_txt DIV.active');
    if ( $active.length == 0 ){
    	$active = $('#hero_media A:last');
    }
    if ($activetxt.length == 0 ){
    	$activetxt = $('#hero_media_txt DIV:last');
    }
    
    var $next    =  $active.next().length ? $active.next() : $('#hero_media A:first');
    var $nexttxt =  $activetxt.next().length ? $activetxt.next() : $('#hero_media_txt DIV:first');

    $active.addClass('last-active');
    $next.css({opacity: 0.0})
         .addClass('active')
         .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
    $activetxt.addClass('last-active');
    $nexttxt.addClass('active');
    $activetxt.removeClass('active last-active');
}
function getJSVars(url){
   var head = document.getElementsByTagName("head")[0];	
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   head.appendChild(e); 
//   alert('jere');
//	 document.write(unescape("%3Cscript src='" + url + "' type='text/javascript'%3E%3C/script%3E"));
}

//function ajaxsubmit(str,action,frmstr){
//	$('#' + str).ajaxStart(function(){
//		document.getElementById(str).innerHTML = 'Processing...';
// 	});
//	$.post(action + $(frmstr).serialize(),{},
//		function(data){
//			d = document.getElementById(str);
//			d.innerHTML = data;
//			//alert(d);
//		}
//	);
//}
$.ajaxSetup ({
    // Disable caching of AJAX responses */
    cache: false
});

function pinItem(item,obj,dom){
//	$.cookie('pins',null,{expires: 1,domain: 'meejam.com'});
//	obj.parentNode.parentNode.style.right = '20px';
	obj.parentNode.parentNode.style.width = '40px';
	obj.parentNode.parentNode.style.background = 'blue';
//	alert(obj.parentNode.parentNode);
	obj.innerHTML = 'Pinned';

	coks = $.cookie('pins');
	item_array = new Array();
	if(coks != null){
		item_array.push(coks);		
		if(coks.indexOf(item) == -1){
			item_array.push(item);
		}
	}
	else{
		item_array.push(item);
	}
	$.cookie('pins',item_array,{expires: 1, path: '/',domain: 'meejam.com'});
	refPinCnt();
}
function refPinCnt(){
	coks = $.cookie('pins');
	cnt = 0;
	if(coks != null){
		ele = coks.split(",");
		cnt = ele.length;
	}
	$('#pincnt').html(cnt);
	return cnt;
}
//accepts jquery objects
function checkall(parentcheckbox,checkboxes,ischeckbox){
	if(ischeckbox){
		if(parentcheckbox.get(0).checked) parentcheckbox.get(0).checked = false;
		else parentcheckbox.get(0).checked = 'checked';
	}
	checkboxes.each(function(){
		if(parentcheckbox.get(0).checked){
			this.checked = 'checked';
		}
		else{
			this.checked = false;
		}
	})
}
function checkpinstr(str){
	coks = $.cookie('pins');
	if(coks != null){
		ele = coks.split(",");
		cnt = ele.length;
		z =  false;
		for(u=0;u<cnt;u++){
			if(ele[u]==str){
				z = true;
				break;
			}
		}
		return z;
	}
	else{
		return false;
	}
}
$(document).ready(function(){
	coks = $.cookie('pins');
	if(coks != null){
		refPinCnt();
	}
});
function getcommadelimchecked(obj){
	str = '';
	for(i=0;i<obj.length;i++){
		if(obj.get(i).checked){
			str = str + obj.get(i).value + ",";
		}
	}
	str = str.substr(0,(str.length-1));
	return str;
}
function getcommadelim(obj){
	cokstr = '';
	for(i=0;i<obj.length;i++){
		cokstr = cokstr + obj.get(i).value + ",";
	}
	cokstr = cokstr.substr(0,(cokstr.length-1));
	return cokstr;
}
function addtofaves(fave,home){
	api = 'http://' + home + '/user/favorites/?do=save&favorites=' + fave + '&jsoncallback=?';
	return $.getJSON(api,function(data){
		if(data){
			alert('It was successfully added to your favorites');
		}
		else{
			alert('Something is wrong');
		}
	})
}
function addtoplaylist(playlist,items,apihome){
	api = 'http://' + apihome + '/user/playlists/?do=add&playlist='+ playlist + '&items='+ items + '&jsoncallback=?';
	return $.getJSON(api,function(data){
		if(data){
			alert('Added to playlist!');
		}
		else{
			alert('Something is wrong');
		}
	})
}
function delfaves(fave,apihome){
	api = 'http://' + apihome + '/user/favorites/?do=del&favorites=' + fave + '&jsoncallback=?';
	return $.getJSON(api,function(data){
		if(data){
			alert('Select Deleted. Your Favorites Is Now Updated.');
		}
		else{
			alert('Something is wrong');
		}
	})
}
function putplaylist2select(obj,apihome){
	url = 'http://' + apihome + '/user/playlists/?do=get&jsoncallback=?';
	$.getJSON(url,function(data){
		if(data){
			for(var i in data){
				obj.append('<option value="' + i + '">' + data[i].name  + '</option>');
			}
		}
	})
}
